C# 访问附加到SharePoint中列表项的资源

C# 访问附加到SharePoint中列表项的资源,c#,sharepoint,C#,Sharepoint,我正在访问SharePoint2013网站上的日历项目列表,如下所示: public ListItemCollection GetListByTitle(string title) { ClientContext context = new ClientContext(_site); List list = context.Web.Lists.GetByTitle(title); ListItemCollection listIte

我正在访问SharePoint2013网站上的日历项目列表,如下所示:

    public ListItemCollection GetListByTitle(string title)
    {
        ClientContext context = new ClientContext(_site);
        List list = context.Web.Lists.GetByTitle(title);
        ListItemCollection listItems = list.GetItems(new CamlQuery()); // Empty CamlQuery to return all items in list
        context.Load(listItems);
        context.ExecuteQuery();
        return listItems;
    }
然后我将ListItemCollection传递给另一个方法,该方法将把该项的一些属性映射到自定义模型

    public List<CustomModel>GetListOfCustomModel(ListItemCollection listItems)
    {
        List<CustomModel> customModelList = new List<CustomModel>();
        foreach(ListItem i in listItems)
        {
            FieldUserValue contact = (FieldUserValue)i.FieldValues["Contact"];
            string s = (string)(contact.LookupValue);
            string t = (string)i.FieldValues["Title"];
            DateTime start = (DateTime)i.FieldValues["EventDate"];
            // etc.
        }
    }
公共ListGetListOfCustomModel(ListItemCollection listItems) { List customModelList=新列表(); foreach(listItems中的ListItem i) { FieldUserValue联系人=(FieldUserValue)i.FieldValue[“联系人”]; 字符串s=(字符串)(contact.LookupValue); 字符串t=(字符串)i.FieldValues[“Title”]; DateTime开始=(DateTime)i.FieldValues[“EventDate”]; //等等。 } } 所有“内置”属性都很容易获得,但我不知道如何访问该公司创建并附加到这些项目的资源

例如,每个日历项都附带一个“房间”资源。我知道这是“元数据”,但我肯定能以某种方式访问它吗?它必须链接到项目,我只是不知道在哪里找。当我为列表中的每一列执行SharePoint列表视图时,我可以看到“文件室”资源作为引用该资源的链接生成


还是我要在web请求中查看我的LISTALL页面,然后使用老式的字符串操作解析文件室,从而查看文本响应

我已经看了几天了,我发现一段代码可以将
ListItemCollection
转换为
DataTable

此代码处理了
Microsoft.SharePoint.Client.FieldLookupValue
Microsoft.SharePoint.Client.FieldUserValue
Microsoft.SharePoint.Client.FieldUserValue[]
但当我查看Excel输出时,我看到了一个
Microsoft.SharePoint.Client.FieldLookupValue[]

再次调试代码并深入到名为
Facilities
FieldLookupValue[]
实例中,瞧,该实例中有房间和所有其他“资源”

简短回答:不要寻找资源,寻找设施

下面是我从另一个回答站点中提取的一些代码,它循环使用
ListItemCollection
并将信息转换为
DataTable
,但经过修改后,显示了FieldUserValue数组的
Id
value
,更重要的是,对
FieldLookupValue
数组也执行同样的操作:

    public DataTable GetDataTableFromListItemCollection(ListItemCollection listItems)
    {
        DataTable dt = new DataTable();
        foreach (var field in listItems[0].FieldValues.Keys)
        {
            dt.Columns.Add(field);
        }

        foreach (var item in listItems)
        {
            DataRow dr = dt.NewRow();

            foreach (var obj in item.FieldValues)
            {
                if (obj.Value != null)
                {
                    string key = obj.Key;
                    string type = obj.Value.GetType().FullName;

                    if (type == "Microsoft.SharePoint.Client.FieldLookupValue")
                    {
                        dr[obj.Key] = ((FieldLookupValue)obj.Value).LookupValue;
                    }
                    else if (type == "Microsoft.SharePoint.Client.FieldUserValue")
                    {
                        dr[obj.Key] = ((FieldUserValue)obj.Value).LookupValue;
                    }
                    else if (type == "Microsoft.SharePoint.Client.FieldUserValue[]")
                    {
                        FieldUserValue[] multValue = (FieldUserValue[])obj.Value;
                        foreach (FieldUserValue fieldUserValue in multValue)
                        {
                            dr[obj.Key] += "&" + fieldUserValue.LookupId + "=" + fieldUserValue.LookupValue;
                        }
                    }
                    else if (type == "Microsoft.SharePoint.Client.FieldLookupValue[]")
                    {
                        FieldLookupValue[] multValue = (FieldLookupValue[])obj.Value;
                        foreach (FieldLookupValue fieldLookupValue in multValue)
                        {
                            dr[obj.Key] += "&" + fieldLookupValue.LookupId + "=" + fieldLookupValue.LookupValue;
                        }
                    }
                    else if (type == "System.DateTime")
                    {
                        if (obj.Value.ToString().Length > 0)
                        {
                            var date = obj.Value.ToString().Split(' ');
                            if (date[0].Length > 0)
                            {
                                dr[obj.Key] = date[0];
                            }
                        }
                    }
                    else
                    {
                        dr[obj.Key] = obj.Value;
                    }
                }
                else
                {
                    dr[obj.Key] = null;
                }
            }
            dt.Rows.Add(dr);
        }

        return dt;
    }