C#Sharepoint客户端对象:读取查找字段 [英] C# Sharepoint Client Object: Reading Lookup Fields

查看:129
本文介绍了C#Sharepoint客户端对象:读取查找字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我想将特定的SharePoint列表读入数据表。我很想阅读查找值。

示例

客户列表,每个客户都分配给团队成员。团队成员查找团队成员列表。



我有以下问题:

1.)如何获取哪个列表链接到此查找字段的信息?

2.)如何读取字段,获取值或索引?





我添加了我的功能下面,非常感谢帮助一个绝望的新手在SharePoint ...



问候



Volker











Hi Guys,

I want to read a specific SharePoint list into a datatable. I am struggeling to read the Lookup Values.
Example:
Customer list, each customer is assigned to a team member. The Team members are a lookup of the Team member list.

I have the following questions:
1.) How can I get the Information which list is linked to this lookup field?
2.) How can read the field, gets the value or the index?


I added my function below, many thanks for helping a desperate novice in SharePoint...

Regards

Volker





public System.Data.DataTable ReadDatafromSPList(ClientContext clientContext, string ListName, string ViewName)
     {
         Web site = clientContext.Web;
         List list = site.Lists.GetByTitle(ListName);
         View view = list.Views.GetByTitle(ViewName);
         ViewFieldCollection viewFields = view.ViewFields;

         clientContext.Load(view);
         clientContext.ExecuteQuery();
         CamlQuery camlQuery = new CamlQuery();
         camlQuery.ViewXml = view.ViewQuery;


        ListItemCollection ListColletion = list.GetItems(camlQuery);
         clientContext.Load(list);
         clientContext.Load(ListColletion);
         clientContext.Load(viewFields);
         clientContext.ExecuteQuery();

        string[] headers  = view.ViewFields.ToArray();
        System.Data.DataTable dTable = new System.Data.DataTable();
        foreach (string header in headers)
            {
                 dTable.Columns.Add(header);
            }


         string str="";

        foreach (ListItem item in ListColletion)
          {
                dTable.Rows.Add(dTable.NewRow());
               foreach (string header in headers)
               {
                   try
                   {
                       str = item[header].ToString();
                       if (str == "Microsoft.SharePoint.Client.FieldLookupValue")
                       {
                         //??????????????????

                        //??????????????????
                       }
                       dTable.Rows[dTable.Rows.Count - 1][header] = str;
                   }
                   catch
                   {
                       dTable.Rows[dTable.Rows.Count - 1][header] = "";
                   }
               }
            }
       return    dTable;
     }

推荐答案

这篇关于C#Sharepoint客户端对象:读取查找字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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