aspx页面从Web服务器上的指定目录下载任何类型的文件 [英] Aspx page to download any type of file from a specific directory on web server
问题描述
我已经从我的客户一个快速的要求,他要在一个文件夹中的一些文件存储在Web服务器(我们有有权让大家一个临时文件夹)。
I had a quick requirement from my client that he want to store some files in a Folder in web server (we have a temp folder which has rights to allow Everybody).
他希望在该文件直接放置和例如给链路 http://www.abcd.com/temp/somefile.rdl 他的客户直接下载该文件。
He want to place the file in that directly and give the link e.g. http://www.abcd.com/temp/somefile.rdl to his customer to directly download the file.
有没有现成的aspx页面可用,这样我就可以使用文件夹的那个页面设置的路径,它应该以这种方式工作。
Is there any readymade aspx page available so that I can just use that page set path of folder and it should work this way.
如果不是我可以只使用aspx页面快速创建它。
If not can I quickly create it using only aspx page.
我几乎在ASPX以下code
I almost did it with the following code in aspx
<%
Response.AppendHeader("Content-Disposition", "attachment; filename=\"" + Server.MapPath("~/TempReport/"+Request.QueryString["file"]) + "\"");
Response.ContentType = "Application/cab";
Response.TransmitFile(Server.MapPath("~/TempReport/"+Request.QueryString["file"]));
Response.End();
%>
唯一的问题是,我只能下载文件的驾驶室类型由于以下行:
The only problem is that I can only download cab type of file due to following line:
Response.ContentType = "Application/cab";
我想任何类型的文件进行下载。
I want any kind of file to be downloaded.
推荐答案
检查这个职位的回答,让这应该为您的内容类型来设置MIME类型
Check this post for answer, to get MIME type which should be set for your content Type
<一个href=\"http://stackoverflow.com/questions/58510/using-net-how-can-you-find-the-mime-type-of-a-file-based-on-the-file-signature\">Using .NET,你怎么能找到基于文件签名的文件的MIME类型而不是扩展
或者你可以把,这应该可以正常下载二进制文件。
Response.ContentType =应用程序/八位字节流;
Or you can just put, which should work fine for downloading binary file. Response.ContentType = "application/octet-stream";
Page.Response.ContentType = "application/octet-stream"
Page.Response.AddHeader("Content-Disposition", "attachment; filename=""" & strFilename & """")
Page.Response.OutputStream.Write(objAttachment.Data, 0, objAttachment.Data.Length)
这篇关于aspx页面从Web服务器上的指定目录下载任何类型的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!