这是我的代码
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 文件,其中包含 readme.txt 文档,其中包含“一些文本”一词。
我得到的是一个名为 filename.zip(预期)的 zip 文件,其中包含文档 readme.txt(预期),文档内没有文本(意外)。
此代码几乎是示例中的逐字逐句here http://dotnetzip.codeplex.com/Wiki/View.aspx?title=Examples。这让我觉得其他人也遇到过这个问题。
我的最终目标是做这样的事情。
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 文件中,但我现在就让示例正常工作。
有人有什么建议吗?
Thanks
- 更新 -
这应该有效,事实上,如果我将它复制到一个新项目中,它的工作原理就像广告中所宣传的那样,我的项目中一定有有毒的 dll 组合或一些损坏,这是晦涩难懂的。精彩的。