Response.TransmitFile腐败文件 [英] Response.TransmitFile corrupting file

查看:96
本文介绍了Response.TransmitFile腐败文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文件在我的服务器或井在这个本地主机。我想用这个code将其传送给用户:

I have a file on my server or well in this localhost. I want to transmit it to user using this code:

        Response.ContentType = "application/pdf";
        Response.AppendHeader("Content-Disposition", "attachment; filename=buylist.pdf");
        Response.TransmitFile(Server.MapPath("~/buylist.pdf"));

        Response.ContentType = "application/csv";
        Response.AppendHeader("Content-Disposition", "attachment; filename=buylist.csv");
        Response.TransmitFile(Server.MapPath("~/buylist.csv"));

我知道我想要传达我们的罚款文件,我甚至尝试添加 Response.Close()但每次文件已损坏。该CSV给我页面的HTML。我真的失去了。

I know the file I am trying to transmit our fine and I even tried adding Response.Close() but each time the file is corrupted. The csv give me the page's HTML. I am really lost.

推荐答案

尝试把一个Response.Clear()在这个code的顶部,而到Response.End()和底部。

Try putting a Response.Clear() at the top of this code, and a Response.End() and bottom.

此外,它看起来像你想在一个响应传输两个文件,​​这是行不通的。这也可能是code在你的问题相同片段呈现出两个版本,但是这仍然是值得一提的:你需要选择一个文件中的一个响应返回。如果你绝对的必须的返回两个文件一次,你必须压缩或者先一起解开它们。没有办法来发送具有相同响应的两个文件。

Also, it looks like you're trying to transmit two files in one response, and that just won't work. It might also be two versions of the code showing in the same snippet in your question, but this is still worth mentioning: You need to pick one file to return in one response. If you absolutely must return two files at once, you'll have to zip or tar them together first. There is no way to send two files with the same response.

这篇关于Response.TransmitFile腐败文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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