简体   繁体   中英

How to get all Site Collections using C# CSOM

My Code:

                SPOSitePropertiesEnumerable spp = null;
                Microsoft.Online.SharePoint.TenantAdministration.Tenant tenant = new Tenant(clientContext);
                int startIndex = 0;

                while (spp == null || spp.Count > 0)
                {
                    spp = tenant.GetSiteProperties(startIndex, true);
                    clientContext.Load(spp);
                    clientContext.ExecuteQuery();

                    foreach (SiteProperties sp in spp)
                    {
                        Response.Write("<br/> All Sites Collection: " + sp.Title + "<br/>");
                       // siteCols.Add(new SiteCol(sp.Title, sp.Url));

                      //  startIndex = siteCols.Count;
                    }
                    startIndex++;
                }

I am getting this Error : Method Microsoft.SharePoint.Client.ClientRuntimeContext.Load: type argument 'Microsoft.Online.SharePoint.TenantAdministration.SPOSitePropertiesEnumerable' violates the constraint of type parameter 'T

Is there any other way to retrieve all site collections?

The error:

Method Microsoft.SharePoint.Client.ClientRuntimeContext.Load: type argument 'Microsoft.Online.SharePoint.TenantAdministration.SPOSitePropertiesEnumerable' violates the constraint of type parameter 'T'.

occurs since there is mismatch between Microsoft.Online.SharePoint.Client.Tenant.dll assembly and the Microsoft.SharePoint.Client.dll assembly versions that are referenced in project.

Microsoft released the following SDKs:

Resolution

Ensure the proper version of Microsoft.Online.SharePoint.Client.Tenant.dll assembly is referenced.

For example, for SharePoint Online project the the following assembly should be referenced: Microsoft.Online.SharePoint.Client.Tenant, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c

类型( 请参阅 ):

Install-Package Microsoft.Sharepoint.2013.Client.16

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM