2013-07-01 78 views
-1

我在Windows應用程序中有網格視圖。現在我想將共享文檔字段值顯示到網格視圖中。任何人都可以有解決方案?如何將Sharepoint文檔庫字段導入GridView

 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; 

錯誤:目錄「共享文檔/照片」並不在現場與URL中Sharepointsite

存在
+0

和你試過嗎? – Mark

+0

添加示例代碼和您堅持的地方,以便任何人都可以幫助您。 – Mark

回答

0

假設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>"; 

,將取回文檔庫中的所有文件夾其中有名稱。

現在,如果你想fieldValue方法的列表,你可以改變你的LINQ查詢到這樣的事情:

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

現在你有所有字段名和它們的值的集合。什麼都可以排序/過濾。

編輯:

如果你想只選擇一個收藏的機會某些領域是一個where子句添加到您的LINQ查詢:

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

我有一個疑問。如何選擇照片文件夾中的特定字段? – Sakthi

+0

請參閱我的編輯,你的意思是這樣的嗎? – Mark

-1

錯誤本身表明問題與該行 變種產品列表= spcontext.Web.Lists.GetByTitle(」共享文件/照片「);