Algorithms in C#  

How to Connect SharePoint Using ASP.Net Core Azure Function

Hey Folks, 

In this article, we will cover the connection between SharePoint and .NET, including all required details. 

In this article, we will see a demonstration where we will fetch data from a SharePoint list using ASP.NET Core API. Also, we will take a short look at Azure Functions, like how to create, and we will see a demo. 

So, before we jump into details, let's check out the prerequisites for our Demo. 

Prerequisites 

  1. Microsoft Azure AD Subscription 

  1. ASP.NET Core V8 is installed in your system 

  1. SharePoint latest version installed (current version is 1.22 but in this, we will use 1.21) 

  1. M365 Subscription to use SharePoint 

  1. Access to the Azure function to upload certificates. 

  1. SharePoint provides access to create sites and lists to access data. 

  1. Require admin consent to grant the Azure function the required permissions to access SharePoint. 

Now, above we have checked out the prerequisites, and it’s time to jump into our detailed article. 

First, in SharePoint, create a List in your desired SharePoint site. Add some data to that list so we can access it via an Azure Function. 

Once you complete the SharePoint list creation with data, we need to create an Azure Function in ASP.NET Core.  

To create an Azure function, we will use the command given below. 

func init MyFunctionAPP --worker-runtime dotnet-isolated
  • Func init – to initialize new azure function project with Isolated worker model. 

  •  MyFunctionAPP – Project Name whatever you want. You can give name as per your project requirements and description. 

  • --worker-runtime dotnet-isolated – Key part of the project. This specifies that create project in Isolated worker model.  

Note - there are mainly two types of functions one is Isolated worker model and second one is In-Process. We are not covering In-Process. We will cover that in another article. 

Then run below command  

cd MyFunctionAPP

go into your project folder. 

func new --name GetSharePointListItems --template "HTTP trigger"
  • Func new – adds new azure function in current project (MyFunctionAPP). 

  • --name GetSharePointListItems – this is the class for function. 

  • --template "HTTP trigger" - this for template. we will use HTTP trigger template. There are different types of templates available for Azure function. 

Once your ran this command it would create a file with extension .cs in your current project.