I wanted to have a link when user clicked, it allow user to download document from SharePoint Document Library.
The link will be placed inside an aspx page.
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开发者_C百科 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. 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. 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.
精彩评论