문제

I load features using the code bellow:

string siteUrl = "http://MyServer/sites/MySiteCollection";

ClientContext clientContext = new ClientContext(siteUrl);
Web site = clientContext.Web;
FeatureCollection collFeature = site.Features;

clientContext.Load(collFeature);
clientContext.ExecuteQuery();

But I also need a scope of each feature. I mean value of FeatureDefinitionScope type. Do you know how load this value via csom ?

도움이 되었습니까?

해결책

With your code, you will only retrieve all features with scope "Web". There is actually a difference between features scoped to a site ("Web" class) or to a site collection ("Site" class).

The following adjusted code retrieves all active features for the site collection and the site:

string siteUrl = "http://MyServer/sites/MySiteCollection";

ClientContext clientContext = new ClientContext(siteUrl);
Site siteCollection = clientContext.Site;
Web site = clientContext.Web;

FeatureCollection siteCollectionFeatures = siteCollection.Features;
FeatureCollection siteFeatures = site.Features;

clientContext.Load(siteCollectionFeatures);
clientContext.Load(siteFeatures);
clientContext.ExecuteQuery();

I'm certain that you won't be able to access WebApplication and Farm features with CSOM (SharePoint client-side object model). As you want to support SharePoint Online, that's your barrier.

If you only want to go for SharePoint OnPremise (SharePoint Foundation or Server), you could go for SSOM (SharePoint server-side object model), which Jerry_MSFT described above. WebApplication features could then be accessed using web.Site.WebApplication.Features (web is your SPWeb class). But you don't have that possibility in CSOM.

다른 팁

In CSOM Feature Object, there is no "FeatureDefinitionScope", please check the documentation:

enter image description here

Feature properties

If you are using SharePoint On-Premise Environment, you can use the Server Object Model below to get this property:

   SPSite site = new SPSite("http://sp/sites/dev/");
    SPWeb web = site.OpenWeb();
    foreach (SPFeature feature in site.Features)
    {
        Console.WriteLine(feature.FeatureDefinitionScope);
    }

enter image description here

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 sharepoint.stackexchange
scroll top