我正在使用以下端点
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下载文档
发布评论