使用SharpZipLib将文件添加到没有路径的ZIP

TTC*_*TCG 14 c# zip sharpziplib

我需要将3个文件合并为1个zip文件,并为用户下载.除了一件事,我能够实现我的要求:它将文件压缩到子文件夹中.

例如,我的文件位置如下:

C:\TTCG\WebSites\Health\ABC.CSV
C:\TTCG\WebSites\Health\XYZ.CSV
C:\TTCG\WebSites\Health\123.CSV
Run Code Online (Sandbox Code Playgroud)

但是在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();
Run Code Online (Sandbox Code Playgroud)

Dav*_*ter 11

根据常见问题解答,您必须手动删除文件夹路径:

如何创建没有文件夹的Zip文件?

在将ZipEntry添加到ZipOutputStream之前,删除用于创建ZipEntry的文件名的路径部分

ZipEntry entry = new ZipEntry(Path.GetFileName(fullPath));

常见问题可以在这里找到.

这似乎是图书馆的一个限制.希望这可以帮助!