Wednesday, March 16, 2016

C# CSOM SharePoint Online Authentication

SharePoint Online authentication via C#.NET Client-side Object Model is simplified with the SharePointOnlineCredentials class. Usage of this has been explained in Vardhaman Deshpande's blog. Usage of this within a Windows Phone app and exception handling is explained in this article.

I have attempted this within a console application as well as in a Windows Phone 8.1 App built using Visual Studio 2013 with Update 5. Basically it will work within Universal Apps.

  • When using the Console Application you need to reference the Microsoft.SharePoint.Client assembly.
  • In order to use this within the Windows Phone Application you need to reference the Microsoft.SharePoint.Client.Runtime assembly. 

The code sample is as follows, in order to proceed with operations, you need to follow the context load and execute query model.
ClientContext context = new ClientContext(siteUrl);
context.Credentials = new SharePointOnlineCredentials(emailAddress, password);
context.AuthenticationMode = ClientAuthenticationMode.Default;

No comments:

Post a Comment