1

I have saved value in list property bag from provider hosted using CSOM code:

list.Context.Load(list.RootFolder);
list.Context.ExecuteQuery();
var properties = list.RootFolder.Properties.FieldValues;
properties["Key"] = Value;
list.RootFolder.Update();
list.Context.ExecuteQuery();

The settings are saved successfully but at the time of retrieving the values from list property bag it shows the key not exist. Code to get key from property bag:

list.Context.Load(list.RootFolder);
list.Context.ExecuteQuery();
string settings = list.RootFolder.Properties.FieldValues.ContainsKey("key")
            ? Convert.ToString(list.RootFolder.Properties["key"])
            : String.Empty;

Kindly suggest where am i doing wrong.

3

How to set property in List

PropertyValue.FieldValues is read-only property, the following example demonstrates how to set property for a List:

var list = ctx.Web.Lists.GetByTitle(listTitle);
var listProperties = list.RootFolder.Properties;
listProperties[key] = value;
list.RootFolder.Update();
list.Context.ExecuteQuery();

How to load properties for a List

var list = ctx.Web.Lists.GetByTitle(listTitle);
ctx.Load(list, l => l.RootFolder.Properties);
ctx.ExecuteQuery();
var pValue = list.RootFolder.Properties[key]; //get property value
  • Thanks a lot Vadim Gremyachev. Can you also suggest how to remove a property from list property bag as there is no method to remove a value from list properties using CSOM ? – Rahul Jain Apr 18 '15 at 8:33
  • You could try something like this: listProperties[key] = null; – Vadim Gremyachev Apr 18 '15 at 8:35

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.