使用 C# 获取 SharePoint 2010 中列表项的查找字段值 [英] Get the lookup field value for a list item in SharePoint 2010 using C#

查看:60
本文介绍了使用 C# 获取 SharePoint 2010 中列表项的查找字段值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 sharepoint 比较陌生,我正在尝试编写一个 Web 服务以将我们的 sharepoint 库存数据作为 xml 返回.除了这些列表之一包含查找字段并且生成的 xml 包含Microsoft.SharePoint.Client.FieldLookupValue"而不是查找字段的预期字符串值之外,它运行良好.

I am relatively new to sharepoint and I'm trying to write a web service to return our sharepoint inventory data as xml. It works good except that one of those list includes a lookup field and the generated xml contains "Microsoft.SharePoint.Client.FieldLookupValue" instead of the expected string value of the lookup field.

这是我用来生成 xml 的代码:

This is the code I'm using to generate the xml:

resultList = remoteWeb.Lists.GetByTitle("Cam Devices");
context.Load(resultList);
context.ExecuteQuery();
//Now its time to reach list's items
items = resultList.GetItems(new CamlQuery());
context.Load(items);
context.ExecuteQuery();
foreach (ListItem item in items)
{
    rootNode.AppendChild(doc.CreateElement("ID")).InnerText = "pcat:401824";
    rootNode.AppendChild(doc.CreateElement("Category")).InnerText = "Cam Devices";
    rootNode.AppendChild(doc.CreateElement("Kimlik")).InnerText = Convert.ToString(item["ID"]);
    rootNode.AppendChild(doc.CreateElement("Isim")).InnerText = Convert.ToString(item["Location0"]) + " >> " + Convert.ToString(item["Brand"]) + " >> " + Convert.ToString(item["ID"]);
}

item["Location"] 是查找字段,它有一个类型为 FieldLookupValue 的值,如何将查找值作为字符串获取?

item["Location"] is the lookup field and it has a value with the type FieldLookupValue, how can I get the lookup value as a string?

推荐答案

好的,使用以下代码语法成功获取查找字段的值:

Ok, successfully get the lookup field's value by using following code syntax:

string Location = "";
if (item["Location0"] != null)
{
    var fl = (SPFieldLookupValue)item["Location0"];
    Location = fl.LookupValue;
}

这篇关于使用 C# 获取 SharePoint 2010 中列表项的查找字段值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆