c# - 使用 C# 在线列出 Sharepoint 上文件夹中的所有文件
问题描述
试图在线列出 Sharepoint 目录中的所有文件。但是在 Microsoft.SharePoint.Client.ServerException 线上得到一个异常:'List 'Shared%20Documents' does not exist at site with URL 'https://MySite.sharepoint.com/sites/TeamSite'。
该目录存在并在检索目录时找到它并在该目录下。不知道这是否是从 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();
};
}
}
}
解决方案
尝试Documents
代替,Shared Documents
或者您始终可以使用context.web.Lists.GetbyID(system.GUID('yourlistguid'))
它的 id 来获取列表
推荐阅读
- c# - Modelstate errors not shown correctly
- rust - 为什么我得到带有向量向量的“没有为类型 Option 找到名为 push 的方法”?
- c++ - Qt3D Project does not show any result after succesful compiling
- php - 首先执行什么?它是php标签内的脚本还是HTML?
- python - using melt function in groupby for large data sets in python
- java - 在单独的线程中定义的绘制函数而不是绘图(Java)
- parsing - Can't fix parsing error for new dropdown menu
- sql - Trying to add image in SQL Server
- jquery - html/jquery - form doesnt submit when its across multiple table td's
- android - 如何保护音乐文件?