简体   繁体   English

c#避免zip文件夹问题

[英]c# avoid zip folder issue

I need to zip a file in the folder c:\\projects\\test\\test.log I need to zip the test.log to a zip folder.I am using Ionic.zip.dll. 我需要将文件c:\\ projects \\ test \\ test.log压缩到一个文件中。我需要将test.log压缩到一个zip文件夹中。我正在使用Ionic.zip.dll。 when I zipped the folder, it is entirely adding the folder c:\\projects\\test\\test.log. 当我压缩文件夹时,它完全是在添加文件夹c:\\ projects \\ test \\ test.log。 I need to add the test.log to a zip folder 我需要将test.log添加到zip文件夹中

for eg.jan.zip. 用于例如jan.zip。 it should contain only one file. 它应该只包含一个文件。 no folder structure needed. 无需文件夹结构。

Thanks 谢谢

Instead of 代替

zipFile.AddFile(filename);

you should use 你应该使用

zipFile.AddFile(filename, "");

That will insert the file at the root of the zip file, ie without a path. 这会将文件插入zip文件的根目录,即没有路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM