{"id":994,"date":"2011-01-27T17:00:35","date_gmt":"2011-01-27T16:00:35","guid":{"rendered":"http:\/\/www.itidea.nl\/?p=994"},"modified":"2015-09-08T20:33:39","modified_gmt":"2015-09-08T18:33:39","slug":"upgrading-a-feature-property","status":"publish","type":"post","link":"https:\/\/www.itidea.nl\/index.php\/upgrading-a-feature-property\/","title":{"rendered":"Upgrading a feature property"},"content":{"rendered":"<p>In SharePoint 2010 features can be upgraded, awesome!<br \/>\nI was just testing this when I discovered something curious when updating a property.<\/p>\n<p>Suppose the following feature definition file:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; ?&gt;\r\n&lt;Feature xmlns=&quot;http:\/\/schemas.microsoft.com\/sharepoint\/&quot; Version=&quot;1.0.0.0&quot;&gt;\r\n\u00a0 &lt;Properties&gt;\r\n\u00a0\u00a0\u00a0 &lt;Property Key=&quot;MyProp&quot; Value=&quot;initialValue&quot; \/&gt;\r\n\u00a0 &lt;\/Properties&gt;\r\n&lt;\/Feature&gt;\r\n<\/pre>\n<p>The property value of the MyProp key \u00a0is &#8220;initialValue&#8221;.<\/p>\n<p>After adjusting the feature definition file to perform an upgrade the file looks like this:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; ?&gt;\r\n&lt;Feature xmlns=&quot;http:\/\/schemas.microsoft.com\/sharepoint\/&quot; Version=&quot;1.1.0.0&quot;&gt;\r\n\u00a0 &lt;UpgradeActions&gt;\r\n\u00a0\u00a0\u00a0 &lt;VersionRange BeginVersion=&quot;1.0.0.0&quot; EndVersion=&quot;2.0.0.0&quot;&gt;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;CustomUpgradeAction Name=&quot;UpgradeToOtherVersion&quot;\/&gt;\r\n\u00a0\u00a0\u00a0 &lt;\/VersionRange&gt;\r\n\u00a0 &lt;\/UpgradeActions&gt;\r\n\u00a0 &lt;Properties&gt;\r\n\u00a0\u00a0\u00a0 &lt;Property Key=&quot;MyProp&quot; Value=&quot;newValue&quot; \/&gt;\r\n\u00a0 &lt;\/Properties&gt;\r\n&lt;\/Feature&gt;\r\n<\/pre>\n<p>And I changed the property value of the MyProp key\u00a0to &#8220;newValue&#8221;.<br \/>\nIn the FeatureUpgrading event receiver I was checking the property value with the following statement:<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\nSPFeatureProperty property1 = properties.Feature.Properties&#x5B;&quot;MyProp&quot;];\r\nstring initalValue = property1.Value;\r\n<\/pre>\n<p>and the result of property1.Value: &#8220;initialValue&#8221; ! I was suprised because I expected &#8220;newValue&#8221;.<\/p>\n<p>After checking some other values and reading documentation on MSDN I came up with the following code to get the new property value:<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\nSPFeatureProperty property2 = properties.Definition.Properties&#x5B;&quot;MyProp&quot;];\r\nstring updatedValue = property2.Value;\r\n<\/pre>\n<p>And the result:<br \/>\n<a href=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2011\/01\/FeatureUpgradeWatchWindow.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-995\" title=\"FeatureUpgradeWatchWindow\" src=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2011\/01\/FeatureUpgradeWatchWindow.png\" alt=\"\" width=\"295\" height=\"83\" \/><\/a><br \/>\nThe difference according to the documentation on MSDN is:<br \/>\nproperties.Feature.Properties[&#8220;MyProp&#8221;] &#8211; Gets the collection of properties for the Feature <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/microsoft.sharepoint.spfeature.properties.aspx\">Link to MSDN<\/a><br \/>\nproperties.Definition.Properties[&#8220;MyProp&#8221;] &#8211; Gets a standardized property bag object that contains per-Feature settings that are specified in the Feature definition <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/microsoft.sharepoint.administration.spfeaturedefinition.properties.aspx\">Link to MSDN<\/a><\/p>\n<p>So I guess my conclusion is:<br \/>\nthe property bag for the feature is updated to the new value after upgrading the feature and the property of the feature isn&#8217;t.<\/p>\n<p>This sounds weird to me and I&#8217;m not sure I understand. Has anyone suggestions or experience with it?<\/p>\n<p>[UPDATE]<br \/>\nWhile tweeting about this issue <a href=\"http:\/\/www.sharepointnutsandbolts.com\/\">Chris O&#8217;Brien <\/a>helped me out on this:<br \/>\nA feature has 1 definition and n instances. The code in FeatureUpgrading is used to upgrade the instances.<br \/>\nThe property in the example updates the feature definition and not the running instances.<br \/>\nSo properties.Feature.Properties[&#8220;MyProp&#8221;] gets the property value of the running instance and properties.Definition.Properties[&#8220;MyProp&#8221;] get the value of the property in the feature definition.<\/p>\n<p>That&#8217;s it and not so weird after all! Thanks Chris!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In SharePoint 2010 features can be upgraded, awesome! I was just testing this when I discovered something curious when updating a property. Suppose the following feature definition file: &lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; ?&gt; &lt;Feature xmlns=&quot;http:\/\/schemas.microsoft.com\/sharepoint\/&quot; Version=&quot;1.0.0.0&quot;&gt; \u00a0 &lt;Properties&gt; \u00a0\u00a0\u00a0 &lt;Property Key=&quot;MyProp&quot; &#8230; <a class=\"more-link\" href=\"https:\/\/www.itidea.nl\/index.php\/upgrading-a-feature-property\/\">Read More &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[20,42,6],"class_list":["post-994","post","type-post","status-publish","format-standard","hentry","category-sharepoint-2010","tag-c","tag-sharepoint-2010","tag-visual-studio"],"_links":{"self":[{"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/posts\/994","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/comments?post=994"}],"version-history":[{"count":6,"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/posts\/994\/revisions"}],"predecessor-version":[{"id":999,"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/posts\/994\/revisions\/999"}],"wp:attachment":[{"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/media?parent=994"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/categories?post=994"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/tags?post=994"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}