0

How can I get a list of property/value pairs of a List? I have the following code:

ClientContext context = new ClientContext("http://lalala.com");
Web web = context.Web;
Guid g = new Guid("lalala");
List list = web.Lists.GetById(g);
foreach (var prop in list.Properties) {
  Console.WriteLine(prop.Name + " " + prop.Value);
}

List properties: https://i.stack.imgur.com/JFvpO.jpg

2 Answers 2

1

first you need to explain what is your code doing? im confused ;)

foreach (var prop in what) {
  // Console.WriteLine(prop.Name + " " + prop.Value);
}

where did what come from? secondly what do you mean by properties? prop.Name + " " + prop.Value to me that means you want to get the values of a list item not the list properties?

to get the list value:

   //list name 
   string listname = list.Title;

do the same for other values!

for the actual list properties (settings)

  SPField field = ((SPList)list).Fields.GetField("Author"); 
object fieldValue = field.GetFieldValue(((SPListItem)item)[field.Title].ToString());

https://stackoverflow.com/questions/647806/accessing-splistitem-properties-in-sharepoint

1
  • I'd like to iterate over, or get properties by name, of the List instance. Not the properties of the List item.
    – Ruudjah
    Apr 4, 2013 at 12:14
0

Here is a way of getting the wanted list correctly from a specified web, and then writing the list properties out in the console screen:

SPSite site = new SPSite(@"http://UrlGoesHere");
SPWeb web = site.RootWeb; //If you have your list in the root level
SPList list = web.Lists.TryGetList("ListNameGoesHere");
var prop = list.PropertiesXml;
Console.WriteLine(prop);
Console.ReadLine();

The output is an XML formatted text.

Your Answer

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

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