我需要将 3 个文件合并为 1 个 zip 文件,并使其可供用户下载。我能够满足我的要求,除了一件事:它将文件压缩到子文件夹中。
例如,我的文件位于以下位置:
C:\TTCG\WebSites\Health\ABC.CSV
C:\TTCG\WebSites\Health\XYZ.CSV
C:\TTCG\WebSites\Health\123.CSV
但在 zip 文件中,它使用“TTCG\WebSites\Health\”作为路径来压缩文件夹中的文件。请看附件。
我不想要路径中的文件夹。我只想要 zip 文件中没有文件夹的 3 个文件。我怎样才能做到这一点?
我生成 zip 文件的代码如下:
ZipFile z = ZipFile.Create(Server.MapPath("~" + @"\Accident.zip"));
//initialize the file so that it can accept updates
z.BeginUpdate();
//add the file to the zip file
z.Add(Server.MapPath("~" + @"\ABC.csv"));
z.Add(Server.MapPath("~" + @"\XYZ.csv"));
z.Add(Server.MapPath("~" + @"\123.csv"));
//commit the update once we are done
z.CommitUpdate();
//close the file
z.Close();