[英]Getting files/folders from sharepoint via the api in c#
I'm trying to link ac# application to a sharepoint directory, so I can create folders, download and upload files.我正在尝试将 ac# 应用程序链接到共享点目录,以便我可以创建文件夹、下载和上传文件。 However I am strugling with connecting to the correct folder.
但是,我正在努力连接到正确的文件夹。
I can retrieve the content from allitems.aspx, but I am not sure how to actually get the content from folder.我可以从 allitems.aspx 检索内容,但我不确定如何从文件夹中实际获取内容。
I have tried using the ClientContext - something like this:我曾尝试使用 ClientContext - 像这样:
ClientContext cxt = new ClientContext("https://xx.sharepoint.com/sites/");
cxt.Credentials = GetCredentials();
List list = cxt.Web.Lists.GetByTitle("Kontrakter");
var test = list.Views;
var test1 = cxt.Web.Lists;
cxt.Load(test1);
cxt.Load(list);
cxt.Load(test);
var a = 4;
var fullUri = new Uri("https://xx.sharepoint.com/sites/yy/Kontrakter/AllItems.aspx");
//var folder = cxt.Web.GetFolderByServerRelativeUrl(fullUri.AbsolutePath);
using (var rootCtx = new ClientContext(fullUri.GetLeftPart(UriPartial.Authority)))
{
rootCtx.Credentials = GetCredentials();
Uri webUri = Web.WebUrlFromPageUrlDirect(rootCtx, fullUri);
using (var ctx1 = new ClientContext(webUri))
{
ctx1.Credentials = GetCredentials();
var list1 = ctx1.Web.GetList(fullUri.AbsolutePath);
ctx1.Load(list1.RootFolder.Files);
ctx1.ExecuteQuery();
Console.WriteLine(list.RootFolder.Files.Count);
}
}
or via normal api calls like this:或通过像这样的普通 api 调用:
https://xx.sharepoint.com/_api/Web/GetFolderByServerRelativeUrl ('Kontrakter/Forms')/Files https://xx.sharepoint.com/_api/Web/GetFolderByServerRelativeUrl ('Kontrakter/Forms')/Files
The only way I can find some data is if I look into 'Shared documents/Forms'我能找到一些数据的唯一方法是查看“共享文档/表单”
I'm having problems understanding the directory structure and how I can actually find the content of files/folders.我在理解目录结构以及如何实际找到文件/文件夹的内容时遇到问题。
Thanks in advance :)提前致谢 :)
原来我在我的一个 uri 中缺少一个 /sites。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.