Archive for December 19, 2011

Remove property from SPPropertyBag

Have you ever tried to remove a property from a SPWeb object and after applying the update, when you next check for the property it is still there?

Logically, you’d think the following code would do this for you:

webObject.Properties.Remove("yourkey");
webObject.Properties.Update();

But, I’ve found, if you reload the SPWeb object and check for the key, it still exists, even though it had been previously removed. To successfully remove a property from the web’s property bag, try setting the property to null, as shown below.

webObject.Properties["yourkey"] = null;
webObject.Properties.Update();

Now when you reload the SPWeb object and check for the property, it won’t exist. It seems that the Remove method is either flaky, or the change is not being persisted after applying the update on the Properties property.

Of course, you really should be using the new AllProperties property instead, where this issue is not present. This property was added to 2010 and uses a HashTable instead of the SPPropertyBag. Items added to AllProperties will filter down to Properties but not the reverse. Most (if not all) of the internal properties use the old Properties property, so there are still certain cases where you’d want to manipulate them. How you work with them is slightly different, for example:

// Remove from old style Properties
webObject.Properties["yourkey"] = null;
webObject.Properties.Update();
 
// Remove from new AllProperties
webObject.AllProperties.Remove("yourkey");
webObject.Update();

Nothing too different, instead of updating the property collection directly you you just update the parent web or site object.

Open with Explorer on Server

If you’re developing with SharePoint using Windows Server 2008 (will work with Windows 7, unless someone’s restricted the Windows Features that are installed) and are unable to open a library via Windows Explorer, follow the simple steps outlined below to enable it.

For example, clicking the Open with Explorer library ribbon menu item, can fail and show the Your client does not support opening this list with Windows Explorer. message.

The enable this functionality, the simplest way is to enable the Desktop Experience feature.
Read more

Follow

Get every new post delivered to your Inbox

Join other followers: