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.
2. Add the NuGet Package SharePointPNPCoreOnline
3. Once, we install, the solution will look like below.
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.
Leave a comment