Click here to Skip to main content
Licence CPOL
First Posted 6 Nov 2009
Views 12,064
Bookmarked 6 times

SharePoint Property Bag

By | 7 Nov 2009 | Technical Blog
Property bag is a feature available in Windows SharePoint Services 3.0. Its nothing but a hash table of Key-Value pairs.
A Technical Blog article. View original blog here.[^]

Property bag is a feature available in Windows SharePoint Services 3.0. Its nothing but a hash table of Key-Value pairs. It allows to add properties to objects in a SharePoint site.

image

Why to Use SharePoint Property Bag

The Property Bag hash table for a site can store any metadata as Key-Value pairs such as connection strings, server names, file paths, and other settings needed by your SharePoint application. Most of the time we will store the above settings in configuration file, which is common to the entire web application. If there is any setting specific each and individual sites in the web application, then we have maintain that many entries in the config file. To over come the above scenario we can use the SharePoint Property Bag.

There is no specific out of box user interface available to set or to read the property bag settings. In WSS 3.0 property bag values has to set/get using the object model. There is an option available in SharePoint designer to set/get the property bag settings. Go to Site -> Site Settings. click on the Parameters tab.  On this tab, you will be able to manipulate of all of your custom property bag values.

image

image

How to Use

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)        
        {            
        }
        });    


License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Rajesh.Sitaraman

Architect
Indian MNC
United States United States

Member

I'm interested in C#, AJAX, SilverLight,and SharePoint now. I enjoy listening to music, movies, driving.
I love posting answers to forums, especially questions related to SharePoint Technology. Started career as c++ developer, then .Net Mobile Technologies and SharePoint now.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
-- There are no messages in this forum --
Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120517.1 | Last Updated 7 Nov 2009
Article Copyright 2009 by Rajesh.Sitaraman
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid