Introduction
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 pieces of code over the Cloud. It helps in processing the data 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 an 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.
Prerequisites
- Microsoft Azure account with Azure functions app.
- SharePoint Online portal
Steps involved
From the Azure portal, create a new function app.
Under the function app, create a new function, using HttpTrigger-CSharp.
Since we are going to work with SharePoint CSOM code, the assembly files need to be uploaded. For the same, set the deployment credentials. From the 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. The Kudu tool page will be opened.
The assembled 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 a 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 the necessary CSOM code. In this sample, we are trying to find the site name of the SharePoint Online site. Everything is hardcoded. The necessary site details and credentials are passed through the CSOM code.
Deploy/ Run
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 the function app URL or through any AJAX REST calls.
Summary
In this article, you have learned about creating Azure functions apps for SharePoint site operations with Managed CSOM code.