문제

SharePoint 라이브러리가 있고 클라이언트 객체 모델을 사용하여 모든 폴더 및 하위 폴더를 트래버스하고 싶습니다. 아무도 해결책을 가질 수 있습니까?

도움이 되었습니까?

해결책

다음 코드는 모든 라이브러리의 모든 라이브러리와 TreeView 에 표시됩니다.

private void frmForm1_Load(object sender, EventArgs e)
{
    using (ClientContext clientcontext= new ClientContext("http://your server"))
    {

        //Load Libraries from SharePoint
        clientcontext.Load(clientcontext.Web.Lists);
        clientcontext.ExecuteQuery();
        foreach (List list in clientcontext.Web.Lists)
        {
           try
           {
                if (list.BaseType.ToString() == "DocumentLibrary" && !list.IsApplicationList && !list.Hidden && list.Title != "Form Templates" && list.Title != "Customized Reports" && list.Title != "Site Collection Documents" && list.Title != "Site Collection Images" && list.Title != "Images")
                {
                    clientcontext.Load(list);
                    clientcontext.ExecuteQuery();
                    clientcontext.Load(list.RootFolder);
                    clientcontext.Load(list.RootFolder.Folders);
                    clientcontext.ExecuteQuery();
                    TreeViewLibraries.ShowLines = true;
                    TreeNode LibraryNode = new TreeNode(list.Title);
                    TreeViewLibraries.Nodes.Add(LibraryNode);
                        foreach (Folder SubFolder in list.RootFolder.Folders)
                        {
                            if (SubFolder.Name != "Forms")
                            {
                                TreeNode MainNode = new TreeNode(SubFolder.Name);
                                LibraryNode.Nodes.Add(MainNode);
                                FillTreeViewNodes(SubFolder, MainNode, clientcontext);
                            }
                        }

                }
            }

        }
    }
}


//Recursive Function

public void FillTreeViewNodes(Folder SubFolder, TreeNode MainNode, ClientContext clientcontext)
{
    clientcontext.Load(SubFolder.Folders);
    clientcontext.ExecuteQuery();
        foreach (Folder Fol in SubFolder.Folders)
        {
            TreeNode SubNode = new TreeNode(Fol.Name);
            MainNode.Nodes.Add(SubNode);
            FillTreeViewNodes(Fol, SubNode, clientcontext);
        }
}
.

요구 사항에 따라 코드를 수정할 수 있습니다. -)

출력 :

여기에 이미지 설명

다른 팁

장면에 충분히 ... 나는 오늘이게 ... 여기에 ...

NetworkCredential credentials = new NetworkCredential("username", "password", "domain");
        ClientContext clientContext = new ClientContext("http://sharepoint/web");
        clientContext.Credentials = credentials;
        CamlQuery query = new CamlQuery();
        query.ViewXml = "<View Scope='Recursive' />";
        ListItemCollection docs = clientContext.Web.Lists.GetByTitle("ListName").GetItems(query);
        clientContext.Load(docs);
        clientContext.ExecuteQuery();
.

그 후에 문서가 반환 된 ListItems를 완료 한 후

public void Main()
    {

        using (var clientContext = new ClientContext(@"https://microsoft.sharepoint.com/teams/PAF/"))
        {

            var passWord = new System.Security.SecureString();
            foreach (char c in "NextGenReport@2014".ToCharArray()) passWord.AppendChar(c);
            clientContext.Credentials = new SharePointOnlineCredentials("smsprpt@microsoft.com", passWord);
            var uploadFilePath = @"G:\\RFY\\SMB\\Weekly Refresh\\SMB_RFY_V1.1 - Weekly Refresh.xlsx";
            using (var fs = new FileStream(uploadFilePath, FileMode.Open))
            {

                var fi = new FileInfo(uploadFilePath);
                var list = clientContext.Web.Lists.GetByTitle("Reports");
                clientContext.Load(list.RootFolder);
                clientContext.Load(list.RootFolder.Folders);
                clientContext.ExecuteQuery();
                Microsoft.SharePoint.Client.File.SaveBinaryDirect(clientContext, "/teams/PAF/Reports/FY15 Reporting/Partner/SMB_RFY_V1.1 - Weekly Refresh.xlsx", fs, true);

            }
        }


        Dts.TaskResult = (int)ScriptResults.Success;
    }
.

스퍼커를 통해 할 수 있습니다.

SPQuery query = new SPQuery();

//Condition to check the item type is folder or not
query.Query = “<Where><Eq><FieldRef Name=’FSObjType’/><Value Type=’Lookup’>1</Value></Eq></Where>”;

//Get all the items including subfolders from the list 
query.ViewAttributes = “Scope=’RecursiveAll’”;
.

이 게시물을 봐

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 sharepoint.stackexchange
scroll top