In this article, you will learn how to create Azure function apps to test SharePoint operations, using Managed CSOM code.
Azure function is a way to run the solutions or piece of code over the Cloud. It helps in processing the data or integrating other systems or even working with the internet of things devices.
In this sample, let us see how to integrate SharePoint operations onto an Azure functions app, using Managed CSOM. Any complex code (CSOM) can be written and executed on the Cloud.
Functions can be triggered in multiple ways. Here, we will create HTTP trigger function. More details and pricing information about Azure functions can be found here.
To start with, I have created a simple Azure function, which retrieves the site title.
Microsoft Azure account with Azure functions app.
SharePoint Online portal
From Azure portal, create a new function app.
Under function app, create a new function, using HttpTrigger-CSharp.
Since we are going to work with SharePoint CSOM code, the assembly files needs to be uploaded. For the same, set the deployment credentials. From function app settings, navigate to the app Service settings.
Get the FTP deployment user name from the app Service settings page.
Set the password for FTP access authentications.
The assembly files can be uploaded in multiple ways. Here, the files are uploaded, using the Kudu tool. From the app Service settings page, select advanced tools under development tools and click Go. Kudu tool page will be opened.
The assemble files should be uploaded to the custom function's bin folder. Navigate to the site -> wwwroot -> Custom function (In this case, it is SPOpsFunction). For SharePoint operations, Microsoft.SharePoint.Client.dll and Microsoft.SharePoint.Client.Runtime.dll files are required. These are the client side reference files, which are required for CSOM operations.
Create new folder called ‘bin’ under the function folder. Now, upload the required files (you can simply drag and drop the files).
Go back to the trigger function created (SPOpsFunction). Copy and paste necessary CSOM code. In this sample, we are trying to find the site name of SharePoint Online site. Everything is hardcoded. The necessary site details and credentials are passed through CSOM code.
Save and run the file. The screenshot given below shows the test pane on the Azure function app portal.
The same can be tested from the Browser by using function app URL or through any AJAX REST calls.
In this article, you have learned about creating Azure functions apps for SharePoint site operations with Managed CSOM code.