我对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
,如何将查找值作为字符串?
答案 0 :(得分:15)
好的,使用以下代码语法成功获取查找字段的值:
string Location = "";
if (item["Location0"] != null)
{
var fl = (SPFieldLookupValue)item["Location0"];
Location = fl.LookupValue;
}