Please refer to the Introduction to PnP Core Component and OfficeDevPnP.Core for more details. I have created a console application and added SharePointPnPCore2016 NuGet package for the SharePoint 2016 version.
Code Snippet
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Microsoft.SharePoint.Client;
- using OfficeDevPnP.Core;
- namespace SP2016PnPCoreComponentDemo
- {
- class Program
- {
- static void Main(string[] args)
- {
- // Input Parameters
- string siteUrl = "http://c7395723754/";
- string userName = "administrator";
- string password = "xxxxxxxxxxx";
- string domain = "AD2012";
- string serverRelativeURL = "/Shared Documents/Folder";
- string localPath = @"C:\Users\Administrator.AD2012\Documents\Folder\Document.rtf";
- string fileName = "UploadedDocument";
- OfficeDevPnP.Core.AuthenticationManager authMgr = new OfficeDevPnP.Core.AuthenticationManager();
- try
- {
- // Get the client context
- using (var ctx = authMgr.GetNetworkCredentialAuthenticatedContext(siteUrl, userName, password, domain))
- {
- // Upload a file to a specific folder
- Folder folder = ctx.Web.GetFolderByServerRelativeUrl(serverRelativeURL);
- folder.UploadFile(fileName, localPath, true);
- }
- }
- catch (Exception ex)
- {
- Console.WriteLine("Error Message: " + ex.Message);
- }
- }
- }
- }

kalu singh raoPosted Jul 1, 2016, 1:47 AM
Nice...