You Can’t Remove an Item from the SPPropertyBag
Hopefully as most of us know by now, the SPWeb class has a property called "Properties" which returns an object of type SPPropertyBag. This is effectively a class sub-classed from the StringDictionary class, and the collection is persisted in the SharePoint content database making it an ideal location to store any custom web-based properties you need to persist.
To store something in the property bag for a web is very easy indeed:
SPWeb web = . . . .
web.Properties.Add("some key", "some value");
This will store a new key-and-value pair in the StringDictionary and then persist the StringDictionary to the SharePoint content database.
You can retrieve the stored value as follows:
String storedValue = web.Properties["some key"];
The problem I've encountered is that it is not possible to remove this key-and-value pair from the StringDictionary. One would expect the following code to perform this action, but it doesn't work.
If you debug this code and interrogate the StringDictionary after the call to the Remove() method, then you will see that the key-and-value pair has indeed been removed, however for some reason it looks as if the call to the Update() method does not handle the removal correctly as this change is not persisted to the content database.
Anyone found a solution for this ??!