Pages

Search This Blog

Friday, April 4, 2014

spweb.properties.remove not working (SPPropertyBag)


This might have bugged a lot of developers that spweb property bag doesn't removes the key when you execute following code

if ( spweb.Properties.ContainsKey(key) )
{
    spweb.Properties.Remove(key);
    spweb.Properties.Update();
}

The Correct code for making sure that property is removed from the from the spweb properties bag is : -

if ( spweb.Properties.ContainsKey(key) )
{
    spweb.AllProperties.Remove(key);
    spweb.Properties[key] = null;
    spweb.Properties.Update();
    spweb.Update();
}