SharePoint and .NET Integration
Create a .Net Web Api Application and then follow the below steps:
Step 1. Open “Tools” from menu and select “NuGet Package Manager” and then click on “Manage NuGet Packages for Solution”. Here is the screenshot:
Step 2. A new tab will open “NuGet Solution”. From this tab search for the following Packages and install them in your project. Here are the Package names you need to install-
-SharePointPnP.IdentityModel.Extensions
-Microsoft.SharePointOnline.CSOM
-SharePointPnPCoreOnline
Step 3. After installing these packages you have to write code where you need to give site url, username and password. Here your site url will be like this – “https://[tenent].sharepoint.com/sites/[SiteName]”
OfficeDevPnP.Core.AuthenticationManager authMgr = new OfficeDevPnP.Core.AuthenticationManager();
using (var ctx = authMgr.GetSharePointOnlineAuthenticatedContextTenant(_siteUrl, _userId, _password))
{
try
{
Web web = ctx.Web;
List list = web.Lists.GetByTitle("Documents"); // fetch all the Files/Folders from Document Library.
ctx.Load(list); //Load the documents
ctx.ExecuteQueryRetry();
}
catch (Exception ex)
{ …. }
}
AuthenticationManager manager class is used to obtain a SharePointContext (ctx ) object. In place of password you can also use (System.Security.SecureString _password) to pass secure string.
