Writing to the Property Bag using CAML in SP2010
Posted
Tuesday, October 20, 2009 10:51 AM
by
CoreyRoth
There are a number of feature improvements in SharePoint 2010. They have made many changes which allow you to do more with features when they are activated or upgraded. One of the new features it the ability to write to the property bag. To do this we just make use of the new PropertyBag element in your elements.xml file. Here is what a file might look like that writes to the property bag. As usual, I’ll point out that features or syntax could change.
<Elements xmnlns="http://schemas.microsoft.com/sharepoint/">
<PropertyBag ParentType="Web">
<Property Name="MyCustomProperty1" Value="some value" />
<Property Name="MyCustomProperty2" Value="4" />
</PropertyBag>
</Elements>
I will point out that whatever type you initialize the property with, it will become semi-permanent. Currently, this applies for integers and date/time. If you try to save another type in an existing property later, you will end up with a null value being stored. This will save me some time in the future as I have had to write code to do this in the past.