简体   繁体   English

如何在SharePoint中以编程方式下载文档?

[英]How to download Document programmatically in SharePoint?

I wanted to have a link when user clicked, it allow user to download document from SharePoint Document Library. 我想在用户单击时提供一个链接,它允许用户从SharePoint文档库下载文档。

The link will be placed inside an aspx page. 链接将放置在aspx页面内。

I tried the function below: 我尝试了以下功能:

Response.ContentType = "application/xls";
Response.AppendHeader("Content-Disposition", "attachment; filename=abc.xls");
Response.TransmitFile(Server.MapPath("~/abc.xls"));
Response.End();

It allow me to download the document successfully, but the downloaded document cannot open. 它可以使我成功下载文档,但是无法打开下载的文档。

what is the better way to do this? 什么是更好的方法呢?

Appreciate if you could provide me some references, thank you. 谢谢您能给我一些参考,谢谢。

For your title, Javascript can get the contents of a web.config through an XMLHTTPRequest to the server, where the server is sending that file. 对于您的标题,Javascript可以通过XMLHTTPRequest向服务器发送该文件的服务器获取web.config的内容。 Of course, that's a security risk and I can't think of any reason a person would want to do that. 当然,这是安全隐患,我想不出任何人愿意这样做的原因。

As for you Excel file, I would suggest using a Content-Type of "application/octet-stream" for binary responses. 至于您的Excel文件,建议对二进制响应使用Content-Type为“ application / octet-stream”。 The browser will then simply save the binary content under the specified file name and let the program (in this case, Excel) take care of interpretting it. 然后,浏览器将简单地将二进制内容保存在指定的文件名下,并让程序(在这种情况下为Excel)负责解释它。

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

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