Click here to Skip to main content
14,085,597 members
Rate this:
 
Please Sign up or sign in to vote.
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





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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web01 | 2.8.190518.1 | Last Updated 12 Jul 2014
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100