【问题标题】:List files all files in folder on Sharepoint online with C#使用 C# 在线列出 Sharepoint 上文件夹中的所有文件
【发布时间】:2021-09-22 13:57:49
【问题描述】:

尝试在线列出 Sharepoint 目录中的所有文件。但是在 Microsoft.SharePoint.Client.ServerException: 'List 'Shared%20Documents' does not exist at site with URL 'https://MySite.sharepoint.com/sites/TeamSite'. em>

该目录存在并在检索目录时找到它并在该目录下。不知道这是否是从 Sharepoint 在线检索文件的正确方法。

using Microsoft.SharePoint.Client;
using OfficeDevPnP.Core;
using System.Collections.Generic;
using System.IO;

namespace Sharepoint
{
class Program
{
    static void Main(string[] args)
    {
        string siteUrl = "https://MySite.sharepoint.com/sites/TeamSite";
        List<ListItem> items = new List<ListItem>();

        using (var clientContext = new AuthenticationManager().GetAppOnlyAuthenticatedContext(siteUrl, appId, AppSecred))
        {
            Web web = clientContext.Web;

            clientContext.Load(web);
            clientContext.Load(web.Lists);
            clientContext.Load(web, wb => wb.ServerRelativeUrl);
            clientContext.ExecuteQuery();

            Folder folder = web.GetFolderByServerRelativeUrl(web.ServerRelativeUrl + "/Shared%20Documents/Testfolder/");
            clientContext.Load(folder);
            clientContext.ExecuteQuery();

            List list = web.Lists.GetByTitle("Shared%20Documents");
            clientContext.Load(list);
            clientContext.ExecuteQuery(); //Throws an exception. Microsoft.SharePoint.Client.ServerException: 'List 'Shared%20Documents' does not exist at site with URL 'https://MySite.sharepoint.com/sites/TeamSite'.'

            CamlQuery camlQuery = new CamlQuery();
            camlQuery.ViewXml = @"<View Scope='Recursive'><Query></Query></View>";
            camlQuery.FolderServerRelativeUrl = folder.ServerRelativeUrl;
            ListItemCollection listItems = list.GetItems(camlQuery);
           
            // Todo
            clientContext.Load(listItems);
            clientContext.ExecuteQuery();
        };
    }
}

}

【问题讨论】:

  • 您是否尝试过使用文字名称Shared Documents,而不是转义的名称?另请注意,该 url 将是该列表的初始名称,但如果您可以更改该列表的标题
  • 是的,但结果相同。不幸的是,目录名称中必须有一个空格。在前面的步骤上工作,所以不要认为这是问题。

标签: c# sharepoint


【解决方案1】:

尝试使用Documents 而不是Shared Documents,或者您可以随时使用context.web.Lists.GetbyID(system.GUID('yourlistguid')) 通过其ID 获取列表

【讨论】:

    猜你喜欢
    • 2023-01-13
    • 2019-02-09
    • 1970-01-01
    • 2013-05-01
    • 2019-11-02
    • 2020-04-26
    • 2020-07-02
    • 1970-01-01
    • 2018-10-23
    相关资源
    最近更新 更多