Updated: Mar 18, 2019
Azure Functions is used for executing a small piece of code or “function” in a cloud and you pay only for the time your code executes. You can use development language of choice, such as C#, F#, PHP, Java etc. Some of the key features of Functions are choice of language, Pay-per-use pricing model, ability to bring your own dependencies, integrated security, simplified integration, flexible development, and open-source. Please refer Azure Functions for more details. Also, you can read my previous articles related to Azure Functions below:
In this article, you will see how to create an Azure Functions app to delete SharePoint Online list using CSOM that will run whenever an HTTP request is received.
Create Azure Functions app on the Azure portal
Log in to the Azure Portal.
Click New-> Compute -> Function App.
Enter all the required details and click Enter.
The Functions app will be provisioned within a few minutes.
Click Function Apps->AzureFunctionsExamples (which you have created) -> Functions -> “+” to create a new function.
Click Custom Function.
Select HTTP Trigger -> C#.
Enter the name of the new function and click "Create".
We need to add the dependencies to access the CSOM code. Click Azure Functions app and then click "Platform features".
Click "Advanced tools (Kudu)" under development tools.
Click "CMD" under Debug console.
Click the folder named "site".
Click the function folder.
Create a new folder and name it as bin. Drag and drop the below mentioned DLL files.
Navigate to the function and replace the code in csx with the below code. Save the changes.
using System.Net; using Microsoft.SharePoint.Client;
public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
// parse query parameter
string title = req.GetQueryNameValuePairs()
.FirstOrDefault(q => string.Compare(q.Key, "title", true) == 0)
System.Security.SecureString secureString=new System.Security.SecureString();
foreach(char ch in password)
SharePointOnlineCredentials creds=new SharePointOnlineCredentials(userName, secureString);
using(var ctx=new ClientContext(siteURL))
return list == null
? req.CreateResponse(HttpStatusCode.BadRequest, "Error retreiveing the list")
: req.CreateResponse(HttpStatusCode.OK, "ListDeleted successfully " + title);
Test the function
Click Get function URL and copy the URL.
Append “&title=<listname>” to the copied function URL and enter into the browser. SharePoint Online list will be deleted successfully.
Also, you could test it on the same page by entering the query parameter value and then by clicking Run. You could also trace the logs the output as shown in below screenshot.
Thus, in this article, you saw how to create Azure Functions app to delete SharePoint Online list using CSOM.