Click here to Skip to main content
15,892,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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





C++
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;
     }
Posted
Updated 12-Jul-14 7:40am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900