Winforms 如何将Sharepoint文档库字段放入GridView

Winforms 如何将Sharepoint文档库字段放入GridView,winforms,c#-4.0,sharepoint-2010,Winforms,C# 4.0,Sharepoint 2010,我在Windows应用程序中有网格视图。现在我想在网格视图中显示共享文档字段值。任何人都有解决办法吗 IEnumerable<Sp.ListItem> list; Sp.ClientContext spcontext = new ClientContext("http://Sharepointsite"); Sp.Web spsite = spcontext.Web; Sp.ListCollection lcollect

我在Windows应用程序中有网格视图。现在我想在网格视图中显示共享文档字段值。任何人都有解决办法吗

        IEnumerable<Sp.ListItem> list;
        Sp.ClientContext spcontext = new ClientContext("http://Sharepointsite");
        Sp.Web spsite = spcontext.Web;
        Sp.ListCollection lcollection = spsite.Lists;
        var productlist = spcontext.Web.Lists.GetByTitle("Shared Documents/Photo");
        Sp.CamlQuery cm = new CamlQuery();
        IQueryable<Sp.ListItem> mylist = productlist.GetItems(cm);
        list = spcontext.LoadQuery(mylist);
        spcontext.ExecuteQuery();
        var qry = (from prd in list
                   select new
                   {

                       Name = prd.FieldValues.Values.ElementAt(1).ToString(),
                       Custom = prd.FieldValues.Values.ElementAt(2).ToString(),

                   }).ToList();

        dataGridView1.DataSource = qry;
IEnumerable列表;
Sp.ClientContext spcontext=新的ClientContext(“http://Sharepointsite");
spsite=spcontext.Web;
Sp.ListCollection lcollection=spsite.Lists;
var productlist=spcontext.Web.Lists.GetByTitle(“共享文档/照片”);
Sp.CamlQuery cm=新的CamlQuery();
IQueryable mylist=productlist.GetItems(cm);
list=spcontext.LoadQuery(mylist);
spcontext.ExecuteQuery();
变量qry=(来自列表中的prd
选择新的
{
Name=prd.FieldValues.Values.ElementAt(1).ToString(),
Custom=prd.FieldValues.Values.ElementAt(2).ToString(),
}).ToList();
dataGridView1.DataSource=qry;

错误:Sharepointsite中URL为的站点上不存在列表“共享文档/照片”

错误本身表明此行存在问题
var productlist=spcontext.Web.Lists.GetByTitle(“共享文档/照片”)

假设
Photo
是文档库中的一个文件夹,则不能将其视为列表标题

如果将空Caml查询更改为

var productlist = spcontext.Web.Lists.GetByTitle("Shared Documents");

var folderName = "Photo";


Sp.CamlQuery cm = new Sp.CamlQuery();
cm.ViewXml = "<View Scope=\"RecursiveAll\"> " +
"<Query>" +
   "<Where>" +
   "<And>" +
     "<Eq>" +
       "<FieldRef Name=\"FSObjType\" />" +
       "<Value Type=\"Integer\">1</Value>" +
     "</Eq>" +
     "<Eq>" +
       "<FieldRef Name=\"Title\"/>" +
       "<Value Type=\"Text\">" + folderName + "</Value>" +
     "</Eq>" +
   "</And>" +
   "</Where>" +
 "</Query>" +
 "</View>";
现在您有了一个包含所有字段名及其值的集合。可以对其进行排序/过滤

编辑:

如果只想选择集合的某些字段,一个机会是向linq查询添加where子句:

var qry = (from prd in list.ElementAt(0).FieldValues
           where prd.Key == "Title"
           select new 
           {
               Key = prd.Key,
               Value = prd.Value
           }).ToList();

添加示例代码和您遇到的困难,以便任何人都能帮助您。我有一个疑问。如何选择照片文件夹中的特定字段??
var qry = (from prd in list.ElementAt(0).FieldValues
           where prd.Key == "Title"
           select new 
           {
               Key = prd.Key,
               Value = prd.Value
           }).ToList();