C# 从Sharepoint Online ListItem获取附件

C# 从Sharepoint Online ListItem获取附件,c#,sharepoint,C#,Sharepoint,我正在尝试获取Sharepoint online listItem的附件或其URL。到目前为止,我只找到了解决办法 但问题是,当我浏览附件所在的文件夹时,它是空的。 这非常令人困惑,因为在SharepointClientBrowser中,文件夹不是空的。还应存储在哪里https://scundp.sharepoint.com/sites/list_overview_test/f0/Lists/Testlist2/Attachments/2/Dokument1.png如果不在url为的文件夹中ht

我正在尝试获取Sharepoint online listItem的附件或其URL。到目前为止,我只找到了解决办法

但问题是,当我浏览附件所在的文件夹时,它是空的。 这非常令人困惑,因为在SharepointClientBrowser中,文件夹不是空的。还应存储在哪里
https://scundp.sharepoint.com/sites/list_overview_test/f0/Lists/Testlist2/Attachments/2/Dokument1.png
如果不在url为的文件夹中
https://scundp.sharepoint.com/sites/list_overview_test/f0/Lists/Testlist2/Attachments/2

在我的代码中,我试图将listItem附件的URL写入
newListItem[“AFiles”]。listItem[“Attachments”]。ToString()==“True”
工作正常,因此仅当存在任何附件时才会运行该块。 但是,bool h设置为false,文件夹也被解释为空

我正在使用的Sharepoint加载项具有以下权限:Web-管理、网站集-完全控制。整个网站集的设置“在客户端应用程序中打开文档”处于活动状态


您可以使用
WebRequest
完成此任务,以便从sharepoint网站下载文件:

public void DownloadFile(string serverFilePath, string destPath)
        {
            var url = string.Format("{0}/{1}", ServerURL, serverFilePath);
            createDirectiory(Path.GetDirectoryName(destPath)); // this method creates your directory
            var request = System.Net.HttpWebRequest.Create(url);
            request.Credentials = System.Net.CredentialCache.DefaultCredentials;
            using (var sReader = new StreamReader(request.GetResponse().GetResponseStream()))
            {
                using (var sWriter = new StreamWriter(destPath))
                {
                    sWriter.Write(sReader.ReadToEnd());
                }
            }
        }
如果您希望使用
客户机对象模型
,以下是一些很好的示例:

是的,我只能使用CSOM。谢谢,我会试试,但是如果我没有完整的路径,它会起作用吗。?我的意思是,在我的代码中,我只得到文件名之前的部分。
public void DownloadFile(string serverFilePath, string destPath)
        {
            var url = string.Format("{0}/{1}", ServerURL, serverFilePath);
            createDirectiory(Path.GetDirectoryName(destPath)); // this method creates your directory
            var request = System.Net.HttpWebRequest.Create(url);
            request.Credentials = System.Net.CredentialCache.DefaultCredentials;
            using (var sReader = new StreamReader(request.GetResponse().GetResponseStream()))
            {
                using (var sWriter = new StreamWriter(destPath))
                {
                    sWriter.Write(sReader.ReadToEnd());
                }
            }
        }