How to get the value of a SharePoint list field

I am trying to get the value of a list box using the SharePoint object model. The problem is that the value should be returned as the field name. The following is a snippet of code. The value is returned as "City" instead of the actual name of the city. I know that the value is not "City" because I checked it in the SPListItem Xml property. I tried both the display name and the internal name as a key. I also tried SPField.GetFieldValue, but the same result. What's happening?


SPListItemCollection items = list.GetItems(query);

foreach (SPListItem item in items)
{
    SPField itemField;
    itemField = item.Fields["City"].ToString();   // returns "City" (!?!?)
}

+3
source share
1 answer

Try:

item["City"]

Your code captures the link to the city field itself, and not the field value for this particular SPListItem.

+5

Source: https://habr.com/ru/post/1762893/


All Articles