2016-10-10 7 views
0

내 프로젝트에 SharePoint 클라이언트 API를 사용해야하고 SharePoint에 업로드 된 폴더의 문서를 나열해야합니다. 내 폴더 링크 "https://mydomain.sharepoint.com/sites/blsmtekn/dyncrm/Shared%20Documents/Forms/AllItems.aspx"SharePoint 웹 사이트에서 문서 라이브러리 가져 오기

 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"); 

번째 오류는 사이트 모음의 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

Web.Lists 메서드를 사용하여 내 Lists를 검사 한 결과 내 파일이 "Belgeler"목록 아래에 있음을 확인했습니다. 셰어 포인트 API와 폴더 구조를 이해하는 데 어려움이 있습니다. –