Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have a problem with updating the properties of a sharepoint 2010 feature

this is my code :

using (SPSite site = new SPSite("http://vm-pc:2000"))
        {
            foreach (SPFeatureDefinition def in SPFarm.Local.FeatureDefinitions)
            {

                if (def.Scope == SPFeatureScope.WebApplication)
                {
                    if (def.GetTitle(System.Threading.Thread.CurrentThread.CurrentCulture) == "Configure Site Settings")
                    {
                        ((SPFeatureProperty)def.Properties[0]).Value = "5";
                        def.Properties.Update();
                        def.Update();

                    }
                }
            }
        }

The problem with:

def.Properties.Update();

is it throws an exception:

Updating the properties of a feature definition is not supported.

I can't find a solution to figure out my problem

share|improve this question
add comment

1 Answer 1

You could update the feature definition in the xml if it was deployed via a .wsp and upgrade the feature. This would push the new properties if they were in your feature.xml.

If you open the YOURFEATURENAME.Template.xml file in the Feature node of the feature you want to update in Visual studio, add the new values and then update the feature

<Feature xmlns="http://schemas.microsoft.com/sharepoint/">
   <Properties>
       <Property Key="THE PROPERTY YOU WANT TO UPDATE" Value="THE NEW VALUE" />
   </Properties>
</Feature>
share|improve this answer
    
please can you give me more information ? –  user1859218 Nov 28 '12 at 10:38
    
ok ,that is clear but the problem I want to set this property by code from web part and when i use the update() method of SPFeatureProperty it throw exception : Updating the properties of a feature definition is not supported. –  user1859218 Nov 28 '12 at 11:36
    
In that case you may have to move the values you want to be storing regarding a feature to the property bag of the web instead of the feature property. As it says, its not supported. –  Grooverinthesouth Nov 29 '12 at 12:08
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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