【发布时间】:2009-07-20 11:36:18
【问题描述】:
这是我的代码
private void sendToClient(Dictionary<string, string> reportDic)
{
Response.Clear();
Response.BufferOutput = false;
String ReadmeText = "some text";
Response.ContentType = "application/zip";
Response.AddHeader("content-disposition", "filename=" + "filename.zip");
using (ZipFile zip = new ZipFile())
{
zip.AddEntry("Readme.txt", ReadmeText);
zip.Save(Response.OutputStream);
}
Response.Close();
}
此时,我只是尝试返回一个 zip 文件,其中包含 zip 中的 readme.txt 文档,其中包含“一些文本”字样。
我得到的是一个名为 filename.zip(expected) 的 zip 文件,其中包含一个 readme.txt(expected) 文档,文档内没有文本(意外)。
这段代码几乎是来自示例here 的逐字记录。这让我觉得其他人遇到了这个确切的问题。
我的最终目标是做这样的事情。
private void sendToClient(Dictionary<string, string> reportDic)
{
Response.BufferOutput = false;
Response.ContentType = "application/zip";
Response.AddHeader("content-dispostion", "filename=text.zip");
Response.ContentEncoding = Encoding.Default;
Response.Charset = "";
using (ZipFile zip = new ZipFile())
{
foreach (string key in reportDic.Keys)
{
zip.AddEntry(key, reportDic[key]);
}
zip.Save(Response.OutputStream);
}
Response.Close();
}
将三个字符串作为文件添加到 zip 文件中,但我会先让示例工作现在。
有人有什么建议吗?
谢谢
--更新-- 这应该可以工作,事实上,如果我将它复制到一个新项目中,它就像宣传的那样工作,我的项目中必须有 dll 的有毒混合或一些损坏,这是模糊的或什么的。精彩的。
【问题讨论】:
-
当我尝试使用 iZarc 打开时收到错误的 zip 标头错误,但它会打开并给我一个空文件,而且此 zip 也无法使用 xp 压缩实用程序打开。
-
我已经用一个字符串、一个字节[] 和一个流尝试了“AddEntry”方法。不好。
-
吉姆,你把这个排序了吗?
-
Cheeso,对不起,我没有回复你,我不得不继续另一个项目,这应该只需要一两天的时间。我从来没有解决过这个问题...相反,我让可怜的用户单击 4 个按钮,但我需要快速完成一些事情,因为我有测试人员在等待输出...我明天或星期一可以回去,我希望。
标签: c# asp.net zip response dotnetzip