I'm trying to get the value of a list field using the SharePoint object model. Problem is that what should be the value is coming back as the f开发者_如何学Pythonield name. Code snippet below. The value is coming back as "City" instead of the actual city name. I know the value is not "City" because I checked it in the SPListItem Xml property. I have tried both the display name and the internal name as the key. I also tried SPField.GetFieldValue, but same result. What the heck is going on?
SPListItemCollection items = list.GetItems(query);
foreach (SPListItem item in items)
{
SPField itemField;
itemField = item.Fields["City"].ToString(); // returns "City" (!?!?)
}
Try:
item["City"]
Your code is grabbing a reference to the City Field itself, not the value of the field for that particular SPListItem.
精彩评论