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.

Comments

# Twitter Trackbacks for Writing to the Property Bag using CAML in SP2010 - Corey Roth - DotNetMafia.com - Tip of the Day [dotnetmafia.com] on Topsy.com

Pingback from  Twitter Trackbacks for                 Writing to the Property Bag using CAML in SP2010 - Corey Roth - DotNetMafia.com - Tip of the Day         [dotnetmafia.com]        on Topsy.com

# re: Writing to the Property Bag using CAML in SP2010

Monday, May 23, 2011 12:37 AM by Eran

I wrote a propertyBag to the elements.xml of a webPart.

but i can't find it in the code.

i use that line inside the code:

control.Path = SPContext.Current.Web.Properties["XmlPath"];

and that line in the elements.xml file:

<PropertyBag ParentType="Web">

   <Property Name="XmlPath" Type="string" Value="c:\Users\tag6k\Desktop\engStat.xml"></Property>

 </PropertyBag>

Leave a Comment

(required)
(required)
(optional)
(required)