Working with property bags
1) Definitely make sure that you call update method when you are done adding property bags, otherwise your changes won’t be applied.
curWeb = SPContext.Current.Web;
curWeb.Properties.Add(“MyProperty”, DateTime.Now.ToString());
curWeb.Properties.Update();
2) In some cases I have found that SPWeb.Properties.Remove(“MyProperty”) does not work even if you call update method after. In those case when I set the property value to null , it will be removed from the collection and SPWeb.Properties.ConstainsKey(“MyProperty”) does not return “True” which means it is not there.
curWeb = SPContext.Current.Web;
curWeb.Properties[“MyProperty”]= null;
curWeb.Properties.Update();
To find out if a property bag exists or not simply check this:
if (curWeb.Properties[“MyProperty”] != null)
{
//Exists
}
else
{
// Does not Exist
}