Question

I'm creating low-trust addin for sharepoint and trying to get list of all site collections using CSOM. This code works good for SharePoint Online:

using (var context = GetAppOnlyClientContext(hostUrl)) 
{ 
   var tenant = new Tenant(context); 
   var siteProperties = tenant.GetSiteProperties(0, true); 

   context.Load(siteProperties); 
   context.ExecuteQuery(); 

   var result = siteProperties.ToList(); 
}

But when I'm trying to run this code on SP 2016 instance, I get following exception:

Cannot find stub for type with id {268004ae-ef6b-4e9b-8425-127220d84719}. The specified server may not support APIs used in this operation.

I'm using CSOM version 16.0.

So the question is: Can I receive list of site collection using CSOM? If yes, how can I avoid this error?

Was it helpful?

Solution

For 2016, you can follow the instructions here: https://blogs.msdn.microsoft.com/vesku/2014/06/09/provisioning-site-collections-using-sp-app-model-in-on-premises-with-just-csom/

Except you need to make the following changes:

  1. You don't need step #1 since the update is already applied.
  2. For the powershell script, be sure to change the version is from 15 to 16.
  3. Skip step 3 since the dll's you have already include the needed references to create the sites.
  4. Run this command the same as is documented.
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top