Property Bag in SharePoint

In SharePoint we can store a property value like a Hash table (key- value pair) using custom coding.
This property can be used to set and retrieve at various objects of SharePoint like (SPSite, SPWeb)

Following is a small sample piece of code to set the property value

try
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
//open the web and set the property
using (SPSite spSite = new SPSite(strWebUrl))
{
using (SPWeb spweb = spSite.OpenWeb())
{
spweb.AllowUnsafeUpdates = true;
bool isPropertyFound = spweb.Properties.ContainsKey(propertyKey);
if (isPropertyFound)
{
spweb.Properties[propertyKey] = propertyValue;
}
else
{
spweb.Properties.Add(propertyKey, propertyValue);
}
spweb.Properties.Update();
spweb.Update();
spweb.AllowUnsafeUpdates = false;
}
}
});
}
catch (Exception ex)
{
throw ex;
}