Skip Ribbon Commands
Skip to main content
www.iwkid.com > Blog > Posts > The SPWeb PropertyBag
June 26
The SPWeb PropertyBag

For those of you not familiar with the PropertyBag, it is a place to store metadata or properties for your web sites in SharePoint.  Much like the term "SharePoint," "PropertyBag" actually can refer to two things on the SPWeb object:

Properties - a SPPropertyBag object

AllProperties - a hashtable

I've always used Properties when setting metadata for web sites but I've heard lots of people lately saying that AllProperties is the better place to put things.  The difference is Properties actually returns a subset of AllProperties.  As long as you are consistent with how you are adding/accessing the metadata, you can use either one.

So - why would you use the property bag?

  • Add additional context for your site - if you are on a project site, add the matching id from your LOB systems.  Web Parts can then read that data, connect to your LOB system and return relevant information.
  • In SharePoint, each web doesn't have a web.config to put configuration values in.  The property bag is a nice place to store configuration variables.

So - how do I use the property bag?

  • There is no out of the box web interface to manage property bag values on a SharePoint web site
  • Thanks to Corey, I now know how to manage the property bag in SharePoint Designer!  I can't believe I haven't seen this before:
    PropertyBag 
  • You can use PowerShell to display properties:
    PoSH PropertyBag (view)
    and update properties:
    PoSH PropertyBag (edit)
  • Obviously if you can update the PropertyBag in PowerShell, you can also update them via Web Part, Feature Receiver, etc...

Comments

Persistence - recycle app pool / iisreset

My properties are not persisting when i recycle the app pool or iisreset - how can they be persisted? If they are not persisting, does that then mean they are simply cached on the WFE which has executed the code to add the property only?

If you have any more information about this please let me know.
 on 11/22/2011 5:39 PM

Persistence

I make this to be persistent:

$web = Get-SPWeb "https://myurl/subsite"
$web.AllowUnsafeUpdates = 1
$web.Properties["myproperty"]="newvalue"
$web.Properties.Update()
$web.AllowUnsafeUpdates = 0
 on 1/16/2012 5:00 AM

Add Farm Property

Is there a syntax to add/create a Farm property in PowerShell?
 on 8/7/2012 3:06 PM

Add Comment

Items on this list require content approval. Your submission will not appear in public views until approved by someone with proper rights. More information on content approval.

Your Name


Your URL

Type the Web address: (Click here to test)  

Type the description: 

Title


Body *


Are you spamming me? *


How many times do I want you to spam me? *


Hint:  ZERO

Attachments