[英]Get document libraries in SharePoint WebSite
我需要在項目中使用sharepoint客戶端api,並在上載到sharepoint的文件夾中列出文檔。 我的文件夾位於“ https://mydomain.sharepoint.com/sites/blsmtekn/dyncrm/Shared%20Documents/Forms/AllItems.aspx ”鏈接下
using (ClientContext ctx = new ClientContext("https://mydomain.sharepoint.com/"))
{
string userName = "username";
string password = "password";
SecureString secureString = new SecureString();
password.ToList().ForEach(secureString.AppendChar);
ctx.Credentials = new SharePointOnlineCredentials(userName, secureString);
List list = ctx.Web.Lists.GetByTitle("/Shared Documents/");
CamlQuery caml = new CamlQuery();
caml.ViewXml = @"<View Scope='Recursive'>
<Query>
</Query>
</View>";
caml.FolderServerRelativeUrl = "/sites/blsmtekn/dyncrm/";
ListItemCollection listItems = list.GetItems(caml);
ctx.Load(listItems);
ctx.ExecuteQuery();
}
但是我遇到了類似“列表…網址不存在的網站”之類的錯誤。 如何遞歸獲取文件夾列表和該文件夾下的文件。
從我的頭頂上,我看到了一些錯誤:您的代碼指出,您的庫的名稱為/Shared Documents/
,而最有可能的名稱為Shared Documents
。
請確定您的GetByTitle()
調用的名稱:
List list = ctx.Web.Lists.GetByTitle("Shared Documents");
第二個錯誤是您的網站集的網址錯誤。 它應該是
ClientContext ctx = new ClientContext("https://mydomain.sharepoint.com/sites/blsmtekn/dyncrm/")
另外,您可以刪除caml.FolderServerRelativeUrl = "/sites/blsmtekn/dyncrm/";
因為那是錯誤的。
總的來說,您的代碼應如下所示:
using (ClientContext ctx = new ClientContext("https://mydomain.sharepoint.com/sites/blsmtekn/dyncrm/"))
{
string userName = "username";
string password = "password";
SecureString secureString = new SecureString();
password.ToList().ForEach(secureString.AppendChar);
ctx.Credentials = new SharePointOnlineCredentials(userName, secureString);
List list = ctx.Web.Lists.GetByTitle("Shared Documents");
CamlQuery caml = new CamlQuery();
caml.ViewXml = @"<View Scope='Recursive'>
<Query>
</Query>
</View>";
ListItemCollection listItems = list.GetItems(caml);
ctx.Load(listItems);
ctx.ExecuteQuery();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.