Home > SharePoint > SPPropertyBag

SPPropertyBag

September 23, 2008 Leave a comment Go to comments

          SPWeb object of SharePoint exposes a Field called Properties which is of type SPPropertyBag a sub class of StringDictionaryIt allows you to store Key value String Data within a web

Below are some quick points that will help you in using it.

  • As Mentioned Before it is a StringDictionary, which can only store String values.
  • You need to call the Update() method of the SPWeb.Properties.Update() to persist the value.
  • Same applies while you are removing a value from it.
  • Below code gives you a quick start.
  • If you want to manage this through UI. Refer this link. It’s a fantastic option you will love.

 using (SPSite oSite = new SPSite(http://mysite))
              {

         using (SPWeb oWeb = oSite.RootWeb)

         {
            //Add an Item to Bag

            oWeb.Properties.Add(“Your Key”,“Your Value”);
            //Be sure to Call the Update Method on Properties

            //If you miss this your value wont get Presisted for the

            //Next Run
            oWeb.Properties.Update();

            // To Reterive the Value

            String sMyItem = oWeb.Properties[“SPPropertyBag”];


            //Remove the Value

            //Be sure to Call the Update Method on Properties
            //If you miss this your value wont get Presisted for the

            //Next Run
            oWeb.Properties.Remove(“SPPropertyBag”);
            oWeb.Properties.Update();

         }
       }

Advertisements
Categories: SharePoint Tags: ,
  1. No comments yet.
  1. No trackbacks yet.

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

%d bloggers like this: