TechBubbles Microsoft Technology BLOG

Using Property bag in SharePoint 2010

What is Property bag?

Property bag is basically a hash table of key-value pair options. Property bag feature is available in Windows SharePoint services 3.0. It allows you to add properties to objects in SharePoint site. Property bag helps you to store meta data as key-value pairs example Connection Strings, file paths, server names and other settings in SharePoint application.

Advantages of using Property bag element

Property helps in enabling client classes to add new properties.

Enables you to assign new values to those new properties.

You can read and manage the current values of the properties.

Usually configuration parameters stored in configuration file(Web.config) for the web application.Imagine if you have to maintain many entries in Web.config file for web application and sites in the web application then it is hard to maintain these keys. In this case you should use SharePoint bag. There is no out of the box user interface available for setting and reading the property bag values, however you can download this wsp to have the interface in central admin for setting the property bag values.

You can use SharePoint designer for getting the Property bag settings. Go to Site | Site settings | then click on the parameter tab option. On this tab user will be able to manipulate all of their custom property bag values. The following code allows you set the Property bag values

SPSecurity.RunWithElevatedPrivileges(delegate()
{
try
{
using (SPSite RootSite = new SPSite(URL))
{
using (SPWeb SiteCollection = RootSite.OpenWeb())
{                    
try
{
SiteCollection.AllowUnsafeUpdates = true;
// Get connection string from Property bag
if (SiteCollection.AllProperties.ContainsKey("ConnectionString"))
{
ConnectionString = SiteCollection.AllProperties["ConnectionString"].ToString();
}                        
// Set siteID in the Property bag
SiteCollection.Properties["siteID"] = siteID;
SiteCollection.Properties.Update();
SiteCollection.AllowUnsafeUpdates = false;                        
}
catch (Exception ex) 
{ 
//Handle Exception  
}           
}
}
}
catch(Exception ex)        
{            
}
})

About the author

Kalyan Bandarupalli

My name is kalyan, I am a software architect and builds the applications using Microsoft .NET technologies. Here I am trying to share what I feel and what I think with whoever comes along wandering to Internet home of mine.I hope that this page and its contents will speak for me and that is the reason I am not going to say anything specially about my self here.

1 Comment

TechBubbles Microsoft Technology BLOG

Follow me

Archives

Tag Cloud