2015-06-11 102 views
0

想要構建應用程序(使用SharePoint CSOM)從SharePoint場中獲取所有用戶和SharePoint組。用戶和組必須從場中可能存在的所有網站集中獲取。通過文檔看起來,Site類https://msdn.microsoft.com/en-us/library/microsoft.sharepoint.client.site_methods(v=office.14).aspx只代表一個'單個'SiteCollection。這很棒。但是,在應用程序可以爲每個SiteCollection創建Site對象之前,應用程序需要確定場中存在的所有SiteCollections。是否有類/方法檢索SharPoint場中的所有SiteCollection?SharePoint CSOM

回答

2

如果搜索已啓用,有一種方法,通過使用搜索結果來做到這一點:

KeywordQuery query = new KeywordQuery(site); 
      query.QueryText = string.Format("Path:{0} AND ContentClass:STS_Site", webAppURL); 
      query.RowLimit = 500;//max row limit is 500 for KeywordQuery 
      query.ResultsProvider = SearchProvider.Default; 
      query.EnableStemming = true; 
      query.TrimDuplicates = false; 
      query.AuthenticationType = QueryAuthenticationType.PluggableAuthenticatedQuery; 
      query.KeywordInclusion = KeywordInclusion.AllKeywords; 
      SearchExecutor executor = new SearchExecutor(); 
      ResultTableCollection resultTableCollection = executor.ExecuteQuery(query); 
      var resultTables = resultTableCollection.Filter("TableType", KnownTableTypes.RelevantResults); 
      var resultTable = resultTables.FirstOrDefault(); 

來源:https://sharepoint.stackexchange.com/questions/133073/get-all-site-collections-with-csom

(順便說一句,使用SharePoint Online很容易,你可以使用SPOSitePropertiesEnumerable class。 SharePoint CSOM, retrieving site collections. Limited to 300?

相關問題