我下载从服务器/数据库中通过aspx页面文件。在正确的应用程序在使用内容处置在线文档打开,但文件名相同的网页。我希望要打开的文档中说,微软Word,但与正确的文件名。下面是我使用的code
I am downloading a file from the server/database via aspx page. When using the content-disposition inline the document opens in correct application but the file name is the same as the web page. I want the document to open in say MS Word but with the correct file name. Here is the code that I am using
Response.Buffer = true;
Response.ClearContent();
Response.ClearHeaders();
Response.Clear();
Response.ContentType = MimeType(fileName); //function to return the correct MIME TYPE
Response.AddHeader("Content-Disposition", @"inline;filename=" + fileName);
Response.AddHeader("Content-Length", image.Length.ToString());
Response.BinaryWrite(image);
Response.Flush();
Response.Close();
所以,再一次,我想在MS Word打开了正确的文件的文件名,以便用户可以正确保存/视图文件。
So again, I want the file to open in MS Word with the correct document file name so that the user can properly save/view.
想法?谢谢
下面是ASP.NET code我使用(使用Delphi.NET,但你的想法),这一直对我很好。请注意,我是内容处置
头设置为附件
而不是在线
:
Here is the ASP.NET code I use (using Delphi.NET, but you get the idea), which has been working fine for me. Notice that I am setting the Content-Disposition
header to attachment
instead of inline
:
Response.Clear();
Response.Expires = 0;
Response.ContentType := 'content type here';
Response.AppendHeader('Content-Disposition', 'attachment; filename="' + Path.GetFileName('file name here') + '"');
Response.AppendHeader('Content-Length', file size here);
我的实际code是一个稍微复杂一点,因为我也支持内容编码
响应头为支持客户端 GZIP
和紧缩
COM pression通过接受编码
请求头。
My actual code is a little more complex, as I also support the Content-Encoding
response header for clients that support gzip
and deflate
compression via the Accept-Encoding
request header.