SPWeb.AllProperties vs. SPWeb.Properties – SharePoint 2010

public Hashtable AllProperties { get; }
SPWeb.Properties is a StringDictionary, and doesn’t support casing for keys/values (everything gets converted to lowercase)

[SubsetCallableExcludeMemberAttribute(SubsetCallableExcludeMemberType.UnsupportedSPType)]
public SPPropertyBag Properties { get; }
SPWeb.AllProperties is a Hashtable, and supports a few other datatypes apart from strings (I believe ints and DateTimes are supported)

Instead of working directly with the SPWeb.Properties StringDictionary, SharePoint 2010 now provides four methods to manage properties:

  • SPWeb.GetProperty(Object key):
    This method retrieves the value of the specified property from the AllProperties property that is a key/value pair.
  • SPWeb.AddProperty(Object key, Object value) :
    This method adds a property to the AllProperties property that is a key/value pair.
  • SPWeb.SetProperty(Object key, Object value):
    This method updates the value of the specified property in the AllProperties property.
  • SPWeb.DeleteProperty(Object key):
    This method deletes a property from the AllProperties property that is a key/value pair.

Don’t let the “object” method signature fool you. After adding a boolean value to SPWeb.AllProperties, but when it was later retrieved, it return back as a String instead of a boolean. It’s definitely good to keep in mind that AllProperties might not accept your complex custom object type.

As a final note, just like any other property of SPWeb, you need to call SPWeb.Update() in order to persist the changes to the underlying database and AllProperties is no different, so don’t forget to do so.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s