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(); 
2
  • Is using a property bag a requirement? Commented May 25, 2015 at 4:02
  • @ArsalanShahid How can we do this in feature activation? i dont need at farm level but its per site collection
    – Happy
    Commented May 26, 2015 at 4:58

1 Answer 1

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?

8
  • As of now i dont know any other options so can you give me answers for both scenarios?
    – Happy
    Commented May 24, 2015 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. Commented May 24, 2015 at 13:07
  • How is it done at site level? Any examples?
    – Happy
    Commented May 24, 2015 at 13:23
  • Here are some examples: jainnitin2411.wordpress.com/2012/07/13/sppropertybagstorage Commented May 24, 2015 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
    Commented May 24, 2015 at 16:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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