Saturday, June 15, 2013

SharePoint 2010 Property Bag - Read / Write data to Property Bag


Property Bag = hash table of Key-Value pairs

Read / Write data to Property Bag

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


http://pbs2010.codeplex.com/

No comments:

Post a Comment