Monday, July 23, 2012

Property bag in sharepoint 2010

Sharepoint Property bags :

This is one of the good feature in sharepoint. This feature is already there in MOSS 2007 and it is carried to the latest version Sharepoint 2010 also.

This is basically used to store the key and value pair in hashtable format.

This is something like app.config information in classic ASP.NET.

Property bags can be created / Modified / Deleted from sharepoint designer or using Object model.

Using sharepoint designer :

1. Open a site in SharePoint Designer

2. Go to Site menu click on Site options

3. Site Settings dialog box opens

4. Click on Parameters tab where you can see the list of existing properties

from the same place you can even perform add/modify/delete operations.
















Using sharepoint object model :

using (SPSite RootSite = new SPSite(URL))
{
using (SPWeb web= RootSite.OpenWeb())
{
try
{
web.AllowUnsafeUpdates = true;
// Get Property bag
if (web.AllProperties.ContainsKey("SiteID"))
{
var data = web.AllProperties["SiteID"].ToString();
}
// Set Property bag
web.Properties["SiteID"] = "GUID";
web.Properties.Update();
web.AllowUnsafeUpdates = false;
}
catch (Exception ex)
{
//Throw Exception
}
}
}
NOTE : Property bags can be handled @Farm level, @Web application level, @Site level.

No comments:

Post a Comment