kwizcom banner advertisement

Property Bags in SharePoint 2013 - Store, Retrieve Custom Configurations

As its name suggests, Property bag feature provides a convenient way to store and retrieve custom configurations, instead of having to store them in web.config files. Property bags in SharePoint stores configuration data in the Hash-Table (Key-Value) format. We can store and retrieve properties at the following levels: 
  1. Farm (SPFarm )
  2. Web application (SPWebApplication )
  3. Site collection (SPSite - Doesn't has Property Bag, but you can use SPSite.RootWeb )
  4. Site (SPWeb )
  5. List (SPList )
  6. Folder (SPFolder)
  7. File (SPFile)
  8. List Item (SPListItem)
Property bags can be created, edited and deleted at all of these level.  Property bag keys are case sensitive!

How to use property bag SharePoint?
If your SharePoint application uses any specific setting for each and individual SharePoint object, such as Web Application, Site Collection, Site, etc. you have maintain those entries in the config files. Here is where SharePoint property bags can be a great helper.

There is no out-of-box user interface to manage property bag settings in SharePoint. We use object model codes to set/get properties programmatically. Any method that interacts with SharePoint object properties such as AddProperty, DeleteProperty, GetProperty, SetProperty doesn't has any effect on "Properties" property. You have to access "AllProperties" instead.  "Property" property is available for backward compatibility.

Managing SharePoint Property bag using PowerShell:
Here is an example to manage Property bag at the site level using PowerShell. 
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

$WebURL =""
#Get the Web Object
$Web = Get-SPWeb -Identity $WebURL

#Variables for Key-Value 
$PropertyName ="masterPage"
$PropertyValue ="Crescentv1.Master"

#add property bag in sharepoint 2010/2013
$web.AddProperty($PropertyName,$PropertyValue) #add property bag
Write-host "Created new Property: "$PropertyName

#how to read property bag in sharepoint - query property bag
Write-host "Retrieved $PropertyName Value:" $web.GetProperty($PropertyName)   

#set property bag sharepoint 2010 powershell
$PropertyNewValue ="Crescentv2.Master"
$web.SetProperty($PropertyName, $PropertyNewValue)
Write-host $PropertyName updated with new value:$PropertyNewValue

#Search for a Property
     #access property bag in sharepoint
     write-host Property Found! Value: $web.GetProperty($PropertyName)
#Remove Property from Property Bag
write-host "Property $PropertyName has been deleted!"

#Get all Properties from sharepoint property bag 


Same code can be translated in to C# object model to use with Event Receiver, Web Part, etc - Add new property bag at site collection level: Here is a SharePoint property bag example:
#Get Site collection
SPSite site = new SPSite("http://your-sharepoint-site-url");

//Add new Property bag key and value
//Old Method
//site.Properties.Add("MasterPage", "Crescentv1");

//create property bag in sharepoint
site.AllProperties["MasterPage"] = "Crescentv1.master";
Tips: You can also manage property bag settings using SharePoint Designer!

SharePoint property bag codeplex Tools:
There are some codeplex utilities to manage SharePoint property bag settings.
  3. - Can be used as a Property bag editor,viewer as well

SharePoint property bag access denied!
If you don't have permission to SharePoint objects you can't interact with them. E.g. To access/add SharePoint Farm property bag you must be a  SharePoint farm administrator. You may get "Access Denied" Error if not! Use Elevated Privileges to store and retrieve from such objects.

SharePoint property bag limitations: As its a HashTable - you can store data values up to 4 KB in size limit.
Property Bags in SharePoint 2013 - Store, Retrieve Custom Configurations Property Bags in SharePoint 2013 - Store, Retrieve Custom Configurations Reviewed by Salaudeen Rajack on July 22, 2014 Rating: 5


  1. SPJobDefinition also has a property bag.

  2. Propertybag is NOT available at SPSite, so your list nr 3 at the start of your article could be removed.
    There is propertybag at the rootweb, but that is not an spsite object but an spweb object, so your nr 4 in the list already covers that.


Please Login and comment to get your questions answered!

Powered by Blogger.