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


Sathish Nadarajan
SharePoint MVP
Published On :   16 Jul 2016
Visit Count
Today :  5    Total :   3710
Plan, Migrate, Secure, Report
SharePoint & Office 365 Tool. Simple & Easy to Use. 15-Day Trial!

Sharegate: Kick-Ass Tool
Think Your SharePoint & Office 365 Are Secure ? Find Out Now!


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.

SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Categories

KWizCom Forms App