ASP.Net将文件下载到客户端浏览器
发布时间:2020-05-23 17:57:33 所属栏目:asp.Net 来源:互联网
导读:我正在编写一个简单的测试页面,在按钮点击下载文本文件到浏览器。我得到一个非常奇怪的错误,我从来没有见过。有什么想法吗? 错误发生在’Response.End();’并且文件永远不会访问客户端浏览器 码: string filePath = C:test.txt; FileInfo file = new File
|
我正在编写一个简单的测试页面,在按钮点击下载文本文件到浏览器。我得到一个非常奇怪的错误,我从来没有见过。有什么想法吗? 错误发生在’Response.End();’并且文件永远不会访问客户端浏览器 码: string filePath = "C:test.txt";
FileInfo file = new FileInfo(filePath);
if (file.Exists)
{
Response.ClearContent();
Response.AddHeader("Content-Disposition","attachment; filename=" + file.Name);
Response.AddHeader("Content-Length",file.Length.ToString());
Response.ContentType = "text/plain";
Response.TransmitFile(file.FullName);
Response.End();
}
错误:
解决方法尝试改变它。Response.Clear();
Response.ClearHeaders();
Response.ClearContent();
Response.AddHeader("Content-Disposition","attachment; filename=" + file.Name);
Response.AddHeader("Content-Length",file.Length.ToString());
Response.ContentType = "text/plain";
Response.Flush();
Response.TransmitFile(file.FullName);
Response.End(); (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net – 使用ModalPopupExtender而不必设置TargetContro
- 如何在asp.net页面上的%...%标签内使用c#代码?
- asp.net-mvc – ASP.NET MVC 4移动显示模式停止工作
- asp.net-mvc-4 – GoogleOauth2问题获取Internal Server 50
- 文件上传 – 如何解决邮递员中的文件上传错误?
- asp.net – 错误:“无法读取配置部分’system.webServer /
- 有标签的ASP.NET WebControl吗?
- asp.net-mvc – asp.net mvc如何正确测试控制器
- 将额外的信息与ASP.NET MVC成员关联
- asp.net-core-mvc – 在ASP.NET Core中,通过将身份验证转发
推荐文章
站长推荐
- ASP.NET MVC删除操作链接确认
- asp.net – Page_ClientValidate()与多个Validat
- asp.net-mvc – MVC5 Microsoft.CSharp.RuntimeB
- 在ASP.NET MVC 3中可以使用甜甜圈缓存
- asp.net-mvc – 什么是强类型的视图在ASP.NET MV
- .net – 从控制器返回一个EditorTemplate作为部分
- asp.net – 用于DropDownList的MVC2 EditorTempl
- asp.net-mvc – MVC控制器正在被调用两次
- asp.net – 如何将Controller上的Ajax reqest重定
- asp.net – HttpContext.Current不解析在MVC 4项
热点阅读
