嗨,我已经下载了 Zip 下载所需的 dll 文件。我已成功在服务器目录上下载了多个 pdf 文件,我编写了压缩多个文件的代码并向客户端提供下载选项,但是从 n 个 pdf 文件中,路径 C:\Program 下面缺少最后一个“n”号文件Files (x86)\Common Files\microsoft shared\DevServer\11.0 并且在 zip.Save(Response.OutputStream) -- 代码行上抛出了这个找不到文件的异常。任何类型的帮助表示赞赏。
protected void Btn_DownloadZip_Click(object sender, System.EventArgs e)
{
try
{
string[] filePaths = Directory.GetFiles(Server.MapPath("~/EStatement/"));
List<ListItem> files = new List<ListItem>();
foreach (string filePath in filePaths)
{
files.Add(new ListItem(Path.GetFileName(filePath), filePath));
}//Collecting names of file from specified Path
using (ZipFile zip = new ZipFile())
{
zip.AlternateEncodingUsage = ZipOption.AsNecessary;
zip.AddDirectoryByName("Zip_Statements");
for(int i=0;i<files.Count;i++)
{
string FPtoAdd = files[i].Text;
zip.AddFile(FPtoAdd, "Zip_Statements");
}
Response.Clear();
Response.BufferOutput = false;
string ZipName = string.Format("Zip_{0}", DateTime.Now.ToString("yyyy-MM-dd-HHmmss"));
Response.ContentType = "application/zip";
Response.AddHeader("content-disposition", "attachment; filename=" + ZipName);
zip.Save(Response.OutputStream); //ERROR LINE
Response.End();
}
}
catch (Exception Ex)
{
ExceptionLogging.SendErrorToText(Ex);
}
}