发布ASP.NET项目后,Zip文件无法正常工作 [英] Zip file is not working after publishing ASP.NET project

查看:76
本文介绍了发布ASP.NET项目后,Zip文件无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

发布后正在下载单个文件。但是在发布asp.net项目后,将所有文件作为zip文件下载不起作用。

建议我解决方案



我尝试过:



如果我添加Ionic.Zip.dll则无法正常工作。所以我使用了NuGet软件包DotNetZip



但是在发布项目后它没有工作。



我的代码是,使用Ionic.Zip


;



ZipFile zip = new ZipFile();

if(dt.Rows.Count> 0)

{

foreach(DataRow dr in dt.Rows)

{

zip.AddEntry(dr [Name]。ToString() ,dr [Data]。ToString());

}

}

var zipMs = new MemoryStream();

zip.Save(zipMs);

byte [] fileData = zipMs.GetBuffer();

zipMs.Seek(0,SeekOrigin.Begin);

zipMs.Flush();

Response.Clear();

Response.AddHeader(content-disposition,attachment; filename = docs.zip);

Response.ContentType =application / zip;

Response.BinaryWrite(fileData);

响应。结束();

Downloading single file is working after publishing. But downloading the all the files as zip file is not working after publishing asp.net project.
Suggest me solution

What I have tried:

If I add Ionic.Zip.dll it is not working. So I used NuGet package DotNetZip

But it is not working after publishing the project.

My code is,

using Ionic.Zip;

ZipFile zip = new ZipFile();
if (dt.Rows.Count > 0)
{
foreach (DataRow dr in dt.Rows)
{
zip.AddEntry(dr["Name"].ToString(), dr["Data"].ToString());
}
}
var zipMs = new MemoryStream();
zip.Save(zipMs);
byte[] fileData = zipMs.GetBuffer();
zipMs.Seek(0, SeekOrigin.Begin);
zipMs.Flush();
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=docs.zip ");
Response.ContentType = "application/zip";
Response.BinaryWrite(fileData);
Response.End();

推荐答案

您是否意识到C#代码在服务器上运行,而不是在客户端上运行?

因此,服务器必须可以访问DataTable引用的文件,并正确地进行修改服务器和Ionic DLL文件需要位于服务器上的正确文件夹中(即BIN文件夹)。



如果所有这些似乎都是正确的,那么首先在该代码中添加一个try ... catch块,并使用一些日志代码来监控到底发生了什么 - 我希望你可能会得到一个异常,你需要知道异常是什么以及何时得到它然后才能开始诊断导致问题的原因。
You do realize that C# code runs on the Server, not the client?
So the files your DataTable refers to have to be accessible to the server, and pathed correctly for the server, and the Ionic DLL files need to be in the right folder on the server (i.e. the BIN folder).

If all of that seems to be right, then start by adding a try...catch block to that code, and some logging code to monitor what exactly is happening - I would expect that you are probably getting an exception and you need to know what the exception is and when you get it before you can start diagnosing what is causing the problem.


这篇关于发布ASP.NET项目后,Zip文件无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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