繁体   English   中英

从共享点列表下载项目

[英]Download item from sharepoint list

我必须从共享点列表(www.domain.sharepoint.com/site/appname/List/ListName)中获取一些文件

我可以反序列化指向列表中每个项目的链接,但不能通过链接下载这些项目。

如何下载列表中存储的文件?

谢谢

请使用GetFileByServativeUrl获取文件对象,然后下载文件流,这是一个代码段供您参考:

 using (var clientContext = new ClientContext("https://xxx.sharepoint.com/sites/xxx"))
            {
                clientContext.Credentials = new SharePointOnlineCredentials(userName, securePassword);
                Web web = clientContext.Web;
                clientContext.Load(web, a => a.ServerRelativeUrl);
                clientContext.ExecuteQuery();


                Microsoft.SharePoint.Client.File file = clientContext.Web.GetFileByServerRelativeUrl("/sites/jerrydev/Shared%20Documents/test.png");
                clientContext.Load(file);
                clientContext.ExecuteQuery();
                if (file != null)
                {
                    FileInformation fileInfo = File.OpenBinaryDirect(clientContext, file.ServerRelativeUrl);
                    clientContext.ExecuteQuery();

                    var folderpath = @"c:\downloadfolder";
                    if (!System.IO.Directory.Exists(folderpath))
                    {
                        System.IO.Directory.CreateDirectory(folderpath);
                    }
                    using (var fileStream = new System.IO.FileStream(folderpath + @"\" + file.Name, System.IO.FileMode.Create))
                    {
                        fileInfo.Stream.CopyTo(fileStream);
                    }
                }
}

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM