1

I want to know how to create multiple properties in property bag in sharepoint 2013 management shell. Now i have pretty long list like below

$farm = Get-SPFarm
$propName = "NameOfSite"
$propValue = "http://mysite"
$farm.Properties.Add($propName, $propValue);
$farm.Update()

$propName = "NameOfList"
$propValue = "myList"
$farm.Properties.Add($propName, $propValue);
$farm.Update()

The list is pretty long and i am just showing couple of those. How can i do it more efficiently and also would like to know how i can refer it in my code. Currently i refer these properties like this

SPFarm farm = SPFarm.Local;
var siteUrl = farm.Properties["NameOfSite"].ToString();
var listname = farm.Properties["NameOfList"].ToString(); 
  • Is using a property bag a requirement? – Arsalan Shahid May 25 '15 at 4:02
  • @ArsalanShahid How can we do this in feature activation? i dont need at farm level but its per site collection – Happy May 26 '15 at 4:58
1

You can store any value of any type in property bags, as long as it is serialized. Having said that all custom objects needs to be serialized.

As far as simple key,value stuff, you are pretty much on right track.

Think it over using Farm level property, do you really need to save these settings on configuration db level?

  • As of now i dont know any other options so can you give me answers for both scenarios? – Happy May 24 '15 at 12:46
  • A property bag can hold any object or simply a key/value pair. Either, you can directly save different property bags or have one object (e.g. arraylist) holding list of property bags. Latter requires serializtion while storing. A farm level property bag is stored in configuration database. Now, do you really need to save these property bags at farm level? You can also save it at site level which eventually is saved into content database, minimizing the risk of corrupting configuration database (taking down the whole farm) by storing non-serialized types. – Falak Mahmood May 24 '15 at 13:07
  • How is it done at site level? Any examples? – Happy May 24 '15 at 13:23
  • Here are some examples: jainnitin2411.wordpress.com/2012/07/13/sppropertybagstorage – Falak Mahmood May 24 '15 at 13:35
  • I dont use sharepoint designer so thats out of question.. In your example i cant find code to store the property bag – Happy May 24 '15 at 16:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.