Jean Paul's Blog

There are 2 types of People in the World, One who Likes SharePoint and..

    Advertisements
  • Microsoft MVP

  • MindCracker MVP

  • CodeProject MVP

  • eBook on SharePoint 2010

  • eBook on Design Patterns

  • eBook on Windows Azure

  • NLayers Framework @ CodePlex

  • MSDN Forums

  • .Net vs. Java

    Due to Public Demand
  • Advertisements

SPWeb:: Properties

Posted by Paul on July 2, 2014


While doing real-world programming, we often require to store some values in the site.

For example:

  • Storing the name of user who created the site
  • Storing the type of site

SPWeb::Properties

We can achieve this through Properties property of SPWeb.  This returns a collection of type SPPropertyBag.

IIS Reset Problem

Over the forums I have found that certain people says property bag is cleared on IIS Reset.

I have tested this & In my observation the property values are retained.

class Program
   {
       static void Main(string[] args)
       {
           using (SPSite site = new SPSite(“http://hpvm”))
           {
               SPWeb web = site.AllWebs.Add(“new”);
               web.Properties[“key”] = “value”;
               web.Properties.Update();
               Console.WriteLine(“Created property ‘key’ with ‘value'”);
           }

           Console.WriteLine(“Resetting IIS”);
           IISReset();

           using (SPSite site = new SPSite(“http://hpvm”))
           {
               SPWeb web = site.AllWebs[“new”];
               string value = web.Properties[“key”];
               Console.WriteLine(“Stored value is:” + value);
               Console.ReadKey(false);
           }
       }

You need to create a new console application, add references, change build to 64 bit for testing the application.

image

References

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spweb.properties(v=office.15).aspx

Advertisements

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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s