【问题标题】:Get the lookup field value for a list item in SharePoint 2010 using C#使用 C# 在 SharePoint 2010 中获取列表项的查找字段值
【发布时间】:2018-11-07 18:21:15
【问题描述】:

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

这是我用来生成 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 的值,我怎样才能将查找值作为字符串获取?

【问题讨论】:

标签: sharepoint-2010


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2023-03-24
    • 1970-01-01
    • 2018-08-05
    • 1970-01-01
    • 1970-01-01
    • 2023-03-13
    • 1970-01-01
    • 2020-11-07
    • 1970-01-01
    相关资源
    最近更新 更多