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; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)