Sunday, August 23, 2009

Sharepoint PropertyBag

Sharepoint comes with handfull of option to store the information with ease.When we are thinking about storing configuration information then first item comes to our mind is web.config.But when we look at sharepoint perspective, there is one more usfull option called propertybag is available.It can store the information at different levels such as

• Farm
• Server
• Web Application
• Site Collection
• Site
• List
So we can share the information across different web where a list failed to do that and also able to persist information across farm.

SPWeb exposes two properties to store the information one is AllProperties which equivalent to a hashtable and supports case sensitive keys.Second one is properties (PropertyBag) and no supports for case sensitive keys.
using (SPSite site = new SPSite(SPContext.Current.Web.Url))
using (SPWeb web= site.OpenWeb()) {
// Add a property entry
web.Properties[key] = value;
web.AllProperties[key] = value;

// Remove a property entry
web.Properties[key] = null;
We can also serialize the object and store in the propertybags.Sounds cool !!
You can download Property bag settings from and more details about managing configuration information

No comments: