C# Zip.Save(Response.OutputStream)错误

C# Zip.Save(Response.OutputStream)错误,c#,zipfile,iconic,C#,Zipfile,Iconic,嗨,我已经下载了Zip下载所需的dll文件。我已成功地在服务器目录下下载了多个pdf文件,并编写了多个文件的zip代码,并向客户端提供下载选项,但从n个pdf文件中,路径下方缺少最后一个n个文件 C:\Program Files(x86)\Common Files\microsoft shared\DevServer\11.0 此未找到文件的例外情况已在 Save(Response.OutputStream)——代码行。任何形式的帮助都是非常感谢的 protected void Btn_Down

嗨,我已经下载了Zip下载所需的dll文件。我已成功地在服务器目录下下载了多个pdf文件,并编写了多个文件的zip代码,并向客户端提供下载选项,但从n个pdf文件中,路径下方缺少最后一个n个文件 C:\Program Files(x86)\Common Files\microsoft shared\DevServer\11.0 此未找到文件的例外情况已在 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);
        }
    }
protectedvoid Btn\u DownloadZip\u单击(对象发送者,System.EventArgs e)
{
尝试
{
字符串[]filepath=Directory.GetFiles(Server.MapPath(“~/EStatement/”);
列表文件=新列表();
foreach(文件路径中的字符串文件路径)
{
添加(新列表项(Path.GetFileName(filePath),filePath));
}//正在从指定路径收集文件名
使用(ZipFile zip=new ZipFile())
{
zip.AlternateenCodinguage=ZipOption.as必要时;
zip.AddDirectoryByName(“zip_语句”);

for(int i=0;i获得了输出。最小的错误是我没有在上面的代码中给出下载路径。这就是它抛出异常的原因

字符串FPtoAdd=Server.MapPath(“~/EStatement/”)+“+files[i].Text

这东西帮我做了,谢谢