2016-10-10 12 views
0

私のプロジェクトにはsharepointクライアントapiを使用し、sharepointにアップロードされたフォルダにはドキュメントをリストする必要があります。マイフォルダは、リンク「https://mydomain.sharepoint.com/sites/blsmtekn/dyncrm/Shared%20Documents/Forms/AllItems.aspxSharePoint WebSiteでドキュメントライブラリを入手

 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(); 
     } 

下にあるしかし、私は、「URLでサイトに存在していない...リスト」のようなエラーを取得しています。そのフォルダの下のフォルダとファイルのリストを再帰的に取得するにはどうすればよいですか。

答えて

0

私の頭の上からいくつかの間違いがあります。あなたのコードでは、あなたのライブラリの名前は/Shared Documents/であり、名前はおそらくShared Documentsです。

あなたGetByTitle()呼び出しの名前を修正してください:

List list = ctx.Web.Lists.GetByTitle("Shared Documents"); 

2番目のエラーは、サイトコレクションのURLが間違っていること、です。それは

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(); 
} 
+0

お返事をありがとうしかし、私は、変更後も同じエラーを取得しています:すべてのコードで

すべては次のようになります。 –

+0

あなたのURLはまだ間違っています。 – Marco

+0

私はListをWeb.Listsメソッドでチェックしました。ファイルが "Belgeler"リストの下にあることがわかりました。私はsharepoint apiとフォルダ構造を理解するのが難しいです。 –

関連する問題