-
Notifications
You must be signed in to change notification settings - Fork 0
How do I run the Office 365 Developer Patterns and Practices against SharePoint 2013 On Premises
Most of the samples in Office 365 Developer Patterns and Practices are created against Office 365 MT. This means that they reference the v16 assemblies.
If you want to test these samples against SharePoint 2013 on-premises then you'll need to make some changes to the solution that you want to run. A first step will be setting the site URL of the SharePoint project to your on-premises developer site:
This will result in an error: Unknow SharePoint version.
To fix this problem you'll first need to replace the referenced version 16 assemblies by their version 15 counterparts. Easiest is to delete them from the project and then add references to the v15 assemblies that are part of PnP.
Once that's done there's a final step to take. Open the properties page for the SharePoint project, select the "SharePoint" tab and set the Target SharePoint Version to "SharePoint 2013" as shown below.
Final result will be that the connection error is gone and your developer site moves to status Online:
Some of the samples make use of the SharePointOnlineCredentials class to create a valid clientcontext object. This class however does not work in SharePoint on-premises and as such you need to revert to another approach which essentially comes down to providing a NetworkCredential class as is shown below.
ClientContext clientContext = new ClientContext(siteUrl);
clientContext.Credentials = new System.Net.NetworkCredential(user, password, domain);
If you're using the PnP core library via either NuGet of via the code that you've pulled down you can also make use of the AuthenticationManager class that has the following methods to create a valid clientcontext:
public ClientContext GetSharePointOnlineAuthenticatedContextTenant(string siteUrl, string tenantUser, string tenantUserPassword)
public ClientContext GetAppOnlyAuthenticatedContext(string siteUrl, string realm, string appId, string appSecret)
public ClientContext GetNetworkCredentialAuthenticatedContext(string siteUrl, string user, string password, string domain)
public ClientContext GetADFSUserNameMixedAuthenticatedContext(string siteUrl, string user, string password, string domain, string sts, string idpId)
From above list GetAppOnlyAuthenticatedContext, GetNetworkCredentialAuthenticatedContext and GetADFSUserNameMixedAuthenticatedContext work perfectly fine against on-premises.