我想从共享点URL中获取数据,我将所有splist都移至treeview。最后,当我单击treeview并收到此错误时,我想从此splist获取数据。 “ Web”不包含“ GetList”的定义,找不到可以接受类型为“ Web”的第一个参数的扩展方法“ GetList”(是否缺少using指令或程序集引用?)
我该如何解决这个问题?
我的代码;
private void Form_Load(object sender, EventArgs e)
{
using (ClientContext spContext = new ClientContext(@"http://mysite/username/"))
{
Web spWeb = spContext.Web;
ListCollection spLists = spContext.Web.Lists;
spContext.Load(spLists);
spContext.ExecuteQuery();
List<Items> spListNames = new List<Items>();
foreach(List listItem in spLists)
{
spListNames.Add(new Items {Title=listItem.Title }); ;
}
treeList1.DataSource = spListNames;
}
}
private void treeList1_Click(object sender, EventArgs e)
{
var Title = treeList1.FocusedNode[treeList1.Columns[0]].ToString();
BindGridFromSharePoint(Title);
}
private void BindGridFromSharePoint(string Title)
{
using (ClientContext spContext = new ClientContext(@"http://mysite/username/"))
{
Web spWeb = spContext.Web;
CamlQuery camlQuery = new CamlQuery();
camlQuery.ViewXml = "<View/>";
List spLists = spContext.Web.GetList(@"http://mysite/username/" + Title.Replace(" ", " %20"));
var spSelectedListItems = spLists.GetItems(camlQuery);
spContext.Load(spLists);
spContext.Load(spSelectedListItems);
spContext.ExecuteQuery();
DataTable dt = new DataTable();
foreach (var item in spSelectedListItems)
{
try
{
foreach (var item1 in item.FieldValues)
{
dt.Columns.Add(item1.Key, typeof(string));
}
}
catch (Exception)
{
// throw;
}
DataRow dr1 = dt.NewRow();
foreach (var item1 in item.FieldValues)
{
dr1[item1.Key] = item1.Value;
}
dt.Rows.Add(dr1.ItemArray);
}
gridControl1.DataSource = dt;
}
}
public class Items
{
public string Title { get; set; }
}