Working with Property Bags Programmatically

Posted on Updated on

Property Bags are very powerful, they can store information in an Hash Table in IIS at several levels

Property Bags can be defined in the following levels:

Farm (SPFarm class)
Web application (SPWebApplication class)
Site collection (SPSite class)
Site (SPWeb class)
List (SPList class)

I wrote an Article for 2010 in here, take a look

protected static void AddProperty(SPWeb web, string key, string value)
    web.AllowUnsafeUpdates = true;
    web.Properties[key] = value;
    web.AllProperties[key] = value;
protected void RemoveProperty(SPWeb web, string key)
    web.AllowUnsafeUpdates = true;
    web.Properties[key] = null;

protected string GetPropertyValue(SPWeb web, string key)
    return web.AllProperties.ContainsKey(key) ? web.AllProperties[key].ToString() : null;

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s