开发者

How to Obtain SharePoint List Field Value

开发者 https://www.devze.com 2023-01-14 11:21 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消