Archive

Archive for September 23, 2008

SPPropertyBag

September 23, 2008 Leave a comment

          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();

         }
       }

Categories: SharePoint Tags: ,

SPPropertyBag

September 23, 2008 1 comment

SPWeb object of SharePoint exposes a Field called Properties which is of type SPPropertyBag a sub class of StringDictionary. It 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 a Item to Bag

oWeb.Properties.Add(“SPPropertyBag”,“I can Store a StringValue Here”);


//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();

             }

         }

    

    

Categories: Uncategorized