使用(“Content-Disposition”,“inline; filename =”+ fileName +“”)不显示文件名 [英] Use of (“Content-Disposition”, “inline; filename=” + fileName +“”) not showing the file name

查看:1473
本文介绍了使用(“Content-Disposition”,“inline; filename =”+ fileName +“”)不显示文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



文件名:abc.aspx



我的代码:

Hi,
file name: abc.aspx

my code:

string Path = @"E:\documents\Data20160129110355.xls";
HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";
HttpContext.Current.Response.AppendHeader("Content-Disposition", "inline; filename="+path+"");
HttpContext.Current.Response.TransmitFile(Path);
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.Close();



单击打开,它将成功打开文件,但文件的标题未显示Data20160129110355.xls。它显示了abc.aspx。



如何解决这个问题请回复。


On click of "Open" it will open the file successfully but the header of the file are not showing "Data20160129110355.xls". It's showing abc.aspx.

How to solve this problem please reply.

推荐答案

试试以下代码:

Try with below code:
string Path = @"E:\documents\Data20160129110355.xls";
string sFileName = "Data20160129110355.xls";
Response.Clear();
HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", "attachment; filename=" + sFileName);
HttpContext.Current.Response.RedirectLocation = url;
HttpContext.Current.Response.TransmitFile(Path);
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.Close();


这篇关于使用(“Content-Disposition”,“inline; filename =”+ fileName +“”)不显示文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆