Console Application Using PNP (Patterns and Practices) – SharePoint Office 365

Sathish Nadarajan
 
Solution Architect
July 16, 2016
 
Rate this article
 
Views
9607

In the previous article, we had seen, how to create a console application against a SharePoint Office 365 Site using the Client Side Object Model. In this article, let us see, how to create the same thing using Patterns and Practices (Office Core Dev PNP).

1. Create a new Console Application using Visual Studio 2015.

clip_image002

2. Add the NuGet Package SharePointPNPCoreOnline

clip_image004

3. Once, we install, the solution will look like below.

clip_image006

4. Now, let us go to Program.cs. Add the below code on Program.cs

 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 
 using Microsoft.SharePoint.Client;
 
 namespace Provisioning.Console
 {
     class Program
     {
         static void Main(string[] args)
         {
             OfficeDevPnP.Core.AuthenticationManager authMgr = new OfficeDevPnP.Core.AuthenticationManager();
             string siteURL = "https://sppals.sharepoint.com/sites/VariationPublishingSite";
             string userName = "sathish@sppals.onmicrosoft.com";
             string password = "************";
 
             using (var ctx = authMgr.GetSharePointOnlineAuthenticatedContextTenant(siteURL, userName, password))
             {
                 ctx.Load(ctx.Web);
                 ctx.ExecuteQueryRetry();
                 System.Console.WriteLine(ctx.Web.Title);
             }
 
             System.Console.ReadLine();
         }
     }
 }
 

5. Execute the program. We will get the Web Title.

There are much more Scenarios where PNP plays a crucial role. Let us try to cover one by one on future articles. There are many Extension methods available.

Happy Coding,

Sathish Nadarajan.

Author Info

Sathish Nadarajan
 
Solution Architect
 
Rate this article
 
Sathish is a Microsoft MVP for SharePoint (Office Servers and Services) having 15+ years of experience in Microsoft Technologies. He holds a Masters Degree in Computer Aided Design and Business ...read more
 

Leave a comment