[英]How to add a folder to a folder when creating a zip file in asp using Ionic.Zip
I am able to successfully create a .zip
file using AddDirectoryByName
and AddFile
, my code below :- 我可以使用AddDirectoryByName
和AddFile
成功创建一个.zip
文件,我的代码如下:-
using (ZipFile zip = new ZipFile())
{
zip.AlternateEncodingUsage = ZipOption.AsNecessary;
zip.AddDirectoryByName("A");
zip.AddFile("~/.png", "A");
}
but what happens is that, it creates a folder by name A
and inside it, it adds a file (eg. .png). 但是发生的是,它创建了一个名称为A
的文件夹,并在其中添加了文件(例如.png)。
But I want to place this folder A
inside another created folder called "Root", so now how can I create a folder called Root
to my .zip and add folder A
to that Root
?? 但是我想将此文件夹A
放置在另一个名为“ Root”的已创建文件夹中,因此现在如何在.zip中创建一个名为Root
的文件夹并将文件夹A
添加到该Root
?
Any help thankfully appreciated. 任何帮助表示感谢。
Simply use the full path name when creating a new directory. 创建新目录时,只需使用完整路径名。
using(ZipFile zip = new ZipFile())
{
string directoryA = "Root/A";
string directoryB = "Root/B";
zip.AddEntry($"{directoryA}/readmeA.txt", "Success from Directory A");
zip.AddEntry($"{directoryB}/readmeB.txt", "Success from Directory B");
zip.Save("file.zip");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.