简体   繁体   English

通过c#中的api从sharepoint获取文件/文件夹

[英]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.

相关问题 无法从 C# 和图形资源管理器中的 Sharepoint 图形获取驱动器项目和驱动器文件夹 - Failing to getting Drive items and Drive Folders from Sharepoint Graph in C# and Graph Explorer C#Sharepoint.Client-返回给定子文件夹中的所有文件和文件夹 - C# Sharepoint.Client - Return all files and folders from a given subfolder 通过 c# 读取 C 驱动器中的所有文件和文件夹 - Read all files and folders in C drive via c# 如何从C#中的Google Drive API从所有文件夹中获取所有文件 - How to get all files from all folders from Google Drive API in C# 无法使用 SharePoint 客户端 API 列出文件/文件夹 - Cannot list files/folders with the SharePoint Client API 在 C# 中获取文件和文件夹的透明外壳图标 - Getting transparent shell-icons for files and folders in C# 如何通过C#从SharePoint页面删除ScriptManager - How to remove ScriptManager from SharePoint Page via C# 如何通过asp.net核心中的C#从SharePoint的共享链接读取和下载文件? - How to read and download files from SharePoint's shareable link via using C# in asp.net core? 在C#中获取SharePoint LookUpValue - Getting a SharePoint LookUpValue in C# 如何从C#中的openFileDialog复制选定的文件夹,子文件夹和文件 - How to copy selected folders, subfolders and files from openFileDialog in c#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM