【问题标题】:Get document libraries in SharePoint WebSite获取 SharePoint 网站中的文档库
【发布时间】:2017-02-18 19:51:40
【问题描述】:

我需要在我的项目中使用 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();
        }

但我收到类似“列表...在具有 URL 的站点不存在”之类的错误。如何递归获取该文件夹下的文件夹和文件列表。

【问题讨论】:

    标签: c# sharepoint sharepoint-2010 sharepoint-clientobject


    【解决方案1】:

    从我的脑海中,我看到了一些错误:您的代码指出,您的库的名称是/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();
    }
    

    【讨论】:

    • 感谢您的回复,但更改后我遇到了同样的错误。
    • 我通过 Web.Lists 方法检查了我的列表,我看到我的文件在“Belgeler”列表下。我很难理解 sharepoint api 和文件夹结构。
    • 1. WebApplication (SPWebApplication), 2. SiteCollection (SPSite), 3. Site (SPWeb), 4. List (SPList), 5. ListItem (SPListItem)。 `caml.FolderServerRelativeUrl` 属性仅指 SPList 中的子文件夹。以上是 SharePoint 中父子关系的粗略层次结构。每个 SharePoint 版本都相同。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-26
    • 2023-04-04
    • 1970-01-01
    相关资源
    最近更新 更多