Manipulating SharePoint Property Bag
The SharePoint sites tend to have lots of configurations requested by the user. These configurations can change over time and there is a need to update them without significant effort of rewriting code. As a result, the SharePoint site comes equipped with a property bag. This property bag can also be used for other common setting related to a site this property bag is part of. You can think of data stored in the property bag the same way you think of key/value pair commonly found in web.config or app.config files.
It is good idea to prefix your own properties with some unique prefix so that you can distinguish them from properties used internally by the SharePoint.
The code below using existing site and adds a private value to the property bag.
using Microsoft.SharePoint; using Microsoft.SharePoint.Administration; using System.Collections; using System; class CreateSite { static void Main(string[] args) { if ((args.Length == 0)) { args = new string[7]; args = GetParams(ref args); } AddSPSiteCollection(args); } private static bool AddSPSiteCollection(string[] args) { try { using (SPSite site = new SPSite("http://sharepointsite/mysite")) { using (SPWeb web = site.RootWeb) { foreach (DictionaryEntry entry in web.Properties) { Console.WriteLine("{0} = {1}", entry.Key, entry.Value); } string key = "PropAutoCreator"; if (!web.Properties.ContainsKey(key)) { web.Properties.Add(key, String.Format("Created by {0} at {1}", Environment.UserName, DateTime.Now)); web.AllowUnsafeUpdates = true; web.Properties.Update(); } } } Console.ReadLine(); web.Dispose(); site.Dispose(); return true; } catch (Exception ex) { Console.WriteLine(ex.Message); return false; } } }