1

I've been working on an provider-hosted app that shows all sitecollections in the current Web application (Tenant). I I've done it on Online using SPOSitePropertiesEnumerable but I've been struggling doing it on-prem. The 15 version of microsoft.online.sharepoint.client.tenant gives me an error saying "Specified method is not supported" when executing the query.

The Code I've been using is

using (var context = new ClientContext(uri))
{
    context.Credentials = new System.Net.NetworkCredential(user, securedPassword, domain);
    var tenant = new Tenant(context);

    int startIndex = 0;

    SPOSitePropertiesEnumerable tenantSiteProperties = null;

    while (tenantSiteProperties == null || startIndex > 0)
    {
        tenantSiteProperties = tenant.GetSiteProperties(startIndex, true);
        context.Load(tenantSiteProperties);
        context.ExecuteQuery();

        foreach (SiteProperties sp in tenantSiteProperties)
        {
            //get site title here.      
        }

        startIndex = tenantSiteProperties.NextStartIndex;
    }
}

Is there any setting that I've been missing or feature that needs to be activated for that to work? The farm got the November 2014 CU and I've tried to use this against a site collection of TenantAdministration site type that I've got for other reasons but still get the same error.

My question. Is this even possible using CSOM? If not, is there any other way that I can achieve it?

1 Answer 1

2

SPOSitePropertiesEnumerable is available only for SharePoint Online not for on premise applications.

You can use Search APIs to get all site collection in an on premise webapplication. See below code to start with:

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();

Make sure search service is running, a good crawl system is in place and continuous crawl is enabled.

3
  • 1
    TrimDuplicates=false seems to be very important here, since the search will return only a small subset if missing - any ideas why?
    – Markus
    Mar 24, 2017 at 10:16
  • What DLL assembly can I add to get the "KeywordQuery" etc.? Nov 13, 2017 at 2:31
  • msdn.microsoft.com/library/…
    – Unnie
    Nov 13, 2017 at 14:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.