sábado, 25 de febrero de 2012

SPWeb’s Propertybag

The most common scenario for working with site settings is using the site’s propertybag. There are two different API properties on the SPWeb class – AllProperties (a Hashtable) and Properties (a PropertyBag). Only the AllProperties property should be used, the Properties property is added to SharePoint 2010 in order to provide backwards compatibility with older applications.

The unconventional PropertyBag data type stores its keys in all lowercase, thus not supporting case-sensitive keys, while the conventional Hashtable does support case-sensitive keys. On top of that, while entries added to Properties get propagated to AllProperties with a lowercase key, entries added to AllProperties do not get propagated to Properties.

If you are working with property entries that only your custom application will be reading and writing from, simply always use AllProperties and you will be good to go. However I often find myself having to work with properties that are read or written by SharePoint internals, and SharePoint itself is very inconsistent in its interaction with Web (Site) properties, probably due to its evolving nature being a rather old product as far as software is concerned.

So the best solution that I have come up with to date is to add your entries to both API properties.

 

   1:  // Add a property entry
   2:  web.Properties[key] = value;
   3:  web.AllProperties[key] = value;
   4:  web.Update();
   5:  web.Properties.Update();
   6:   
   7:  // Remove a property entry
   8:  web.AllProperties.Remove(key);
   9:  web.Properties[key] = null;
  10:  web.Update();
  11:  web.Properties.Update();



Fuente:


http://bramnuyts.be/2012/01/10/working-with-spwebs-propertybag/


http://trentacular.com/2009/06/sharepoint-the-wicked-spwebproperties-propertybag/


http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spweb_members.aspx

No hay comentarios:

Publicar un comentario