2

I am working on "Getting properties of SharePoint Feature using CSOM in SharePoint Online".

Following is the code which I wrote :

  try
        {
            Password password = new Password();
            SecureString securePassword = new SecureString();
            securePassword = password.ConvertStringToSecureString();
            using (ClientContext context = new ClientContext("https://mysite"))
            {

                Web web = context.Web;

                FeatureCollection featuresCollection = web.Features;

                context.Load(featuresCollection);

                context.ExecuteQuery();
                foreach (Feature feature in featuresCollection)
                {

                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.WriteLine("Feature Definition ID:{0}", feature.DefinitionId);

                }
            }
        }

There is only one property feature.DefinitionId which I found for the feature object. Is there any way to get the other properties of feature?

PS- Can we do anything with featureDefinitionID and get the Feature Definition XML in Sharepoint Online?

4

CSOM Feature object exposes the following properties:

Such SSOM Feature properties as SPFeature.Definition or SPFeature.Properties are not available in CSOM/REST.

Below examples demonstrate how to manage features using CSOM

Example: how to retrieve activated (web scope) features:

var webFeatures = ctx.Web.Features;
ctx.Load(webFeatures,fcol => fcol.Include(f => f.DisplayName,f => f.DefinitionId));
ctx.ExecuteQuery();
foreach(var f in webFeatures)
{
   Console.WriteLine(f.DisplayName);
}

Example: how to activate a feature

 ActivateWebFeature(ctx.Web, new Guid("94c94ca6-b32f-4da9-a9e3-1f3d343d7ecb"),true); //active a Publishing feature

,where

public static void ActivateWebFeature(Web web, Guid featureId, bool force)
{
    var ctx = web.Context;
    web.Features.Add(featureId, force, FeatureDefinitionScope.None);
    ctx.ExecuteQuery();
}
  • 1
    @saikumar.tammisetty Please mark the answer as accepted if it solves your issue – grisha Jan 23 '15 at 14:58
  • @grisha from my question it self i achived definitionid.but actually am expecting little more.i got an alternative using windows sharepoint services using soap call.am still awaiting for a better solution – saikumar.tammisetty Jan 23 '15 at 15:10
  • 1
    DisplayName is not a Feature Property in CSOM either. – Brian P Jul 21 '15 at 18:59
  • 1
    @BrianP That's just incorrect. I was able to load the DisplayName using the above example by Vadmin-Gremyachev . This should be the accepted answer. – Shailen Sukul Aug 3 '15 at 4:40
  • Which version of the CSOM DLL are you using? I tested in both 15.0.0.0 and 16.0.0.0 – Brian P Aug 3 '15 at 14:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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