使用sharepoint rest api c#httpwebrequest下载文档

编程入门 行业动态 更新时间:2024-10-18 08:24:01
本文介绍了使用sharepoint rest api c#httpwebrequest下载文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用以下端点

url:http:// site url / _api / web / GetFolderByServerRelativeUrl('/ Folder Name')/ Files('file name ')/ $ value 方法:GET

如果我在浏览器中浏览端点,它工作正常。当我尝试使用httpwebrequest和getresponsestream()函数时,它不会返回文件流。

请做必要的

解决方案

以下代码片段供您参考。

var siteURL =" http:// sp2013 / sites / team" ;; var username =" dennis" ;; var password =" password" ;; var domain =" contoso" ;; var folderRelativeUrl =" / sites / team / DL" ;; var fileName =" Test.pdf" ;; HttpWebRequest request = null; HttpWebResponse response = null; string commandString = string.Empty; commandString = string.Format(" / _ api / web / GetFolderByServerRelativeUrl('{0}')/ files('{1}')/

值",folderRelativeUrl,文件名); Uri uri = new Uri(siteURL + commandString); //设置HTTP请求请求=(HttpWebRequest)WebRequest.Create(uri); request.Credentials = new NetworkCredential(用户名,密码,域名); request.Method = WebRequestMethods.Http.Get; response =(HttpWebResponse)request.GetResponse(); if(response.ContentLength> 0)response.ContentLength = response.ContentLength; Stream output = response.GetResponseStream(); using(var fs = new FileStream(" c:\\temp \\" + fileName,FileMode.OpenOrCreate)) output.CopyTo(fs);

更多信息:

social.technet.microsoft/论坛/共享点/ EN-US / f6b1f3c2-d8e5-4d22-8e65-a9519cc02544 /如何到下载一个文件,从SharePoint的-2013-利用休息和-C?论坛= sharepointdevelopment

或者我们也可以使用 WebClient 和REST API从文档库中下载文件。

social.msdn.microsoft/Forums/en-US/f7f1cb7d-4406-4b72-b7f1-dc5dde6c34e1/how-to-download-file-from-document-librar y-using-rest-api?forum = appsforsharepoint

最好的问候,

Dennis

I am using the following endpoint

url: site url/_api/web/GetFolderByServerRelativeUrl('/Folder Name')/Files('file name')/$value method: GET

It is working fine if I browse the endpoint in the browser. When I tried with httpwebrequest and getresponsestream() function it is not returning the file stream.

Please do the needful

解决方案

Hi,

The following code snippet for your reference.

var siteURL = "sp2013/sites/team"; var username = "dennis"; var password = "password"; var domain = "contoso"; var folderRelativeUrl = "/sites/team/DL"; var fileName = "Test.pdf"; HttpWebRequest request = null; HttpWebResponse response = null; string commandString = string.Empty; commandString = string.Format("/_api/web/GetFolderByServerRelativeUrl('{0}')/files('{1}')/

value",folderRelativeUrl,fileName); Uri uri = new Uri(siteURL + commandString); //Set up the HTTP Request request = (HttpWebRequest)WebRequest.Create(uri); request.Credentials = new NetworkCredential(username, password, domain); request.Method = WebRequestMethods.Http.Get; response = (HttpWebResponse)request.GetResponse(); if (response.ContentLength > 0) response.ContentLength = response.ContentLength; Stream output = response.GetResponseStream(); using (var fs = new FileStream("c:\\temp\\"+fileName, FileMode.OpenOrCreate)) output.CopyTo(fs);

More information:

social.technet.microsoft/Forums/sharepoint/en-US/f6b1f3c2-d8e5-4d22-8e65-a9519cc02544/how-to-download-a-file-from-sharepoint-2013-using-rest-and-c?forum=sharepointdevelopment

Or we can also use WebClient with REST APIto download file from document library.

social.msdn.microsoft/Forums/en-US/f7f1cb7d-4406-4b72-b7f1-dc5dde6c34e1/how-to-download-file-from-document-library-using-rest-api?forum=appsforsharepoint

Best Regards,

Dennis

更多推荐

使用sharepoint rest api c#httpwebrequest下载文档

本文发布于:2023-11-28 09:58:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1641936.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文档   rest   sharepoint   httpwebrequest   api

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!