使用ionic.zip.zipfile创建目录 [英] Creating Directory using ionic.zip.zipfile
问题描述
你好,我动态创建html,我正在创建zipfile,如:
using(ZipFile file = new ZipFile()){
file.AddEntry('' SomeFileName''+'''。html',''< div>这是Saad< / div>'');
}
而不是保存zip输出流上的文件。它的工作正常,zip文件下载选项会在浏览器中弹出,并在用户保存的任何地方下载
MyZip.zip-> myhtml1
我需要做的是我想添加一个文件夹并在其中添加html而不是zipit。我无法指定文件夹的路径我也没有html在磁盘上我可以映射它因为html是动态生成的。任何人都可以建议一些解决方案吗?
MyZip.zip-> myFolder1-> myhtml1
MyZip.zip-> myFolder2 - > myhtml2和儿子on
Hello , i am dynamically creating html and i am creating zipfile like:
using(ZipFile file = new ZipFile()){
file.AddEntry(''SomeFileName''+'''.html',''<div>This is Saad</div>'');
}
and than saving the zip file on output stream. Its working fine , zip file download option gets pop up in the browser and is downloaded wherever user saves it
MyZip.zip-> myhtml1
What i need to do is that i want to add a folder and add html into it and than zipit. I can't specify the path for the folder neither i have html on disk that i can map it because html is generating dynamically. Can any one suggest some solution ??
MyZip.zip->myFolder1->myhtml1
MyZip.zip->myFolder2->myhtml2 and son on
推荐答案
在文件名参数中包含文件夹名称:
Include the folder name in the file name parameter:
file.AddEntry("myFolder1/myhtml1.html", "<div>This is Saad</div>");
它没有如果对路径分隔符使用正斜杠( / )或反斜杠( \ ),则无关紧要,因为代码将根据需要修复路径。但是,要使用C#的反斜杠,您需要将其转义,或者使用逐字字符串:
It doesn't matter if you use a forward slash (/) or a backslash (\) for the path separator, as the code will fix up the path as necessary. However, to use a backslash from C#, you'd either need to escape it, or use a verbatim string:
// Escape it:
file.AddEntry("myFolder1\\myhtml1.html", "<div>This is Saad</div>");
// or use a verbatim string:
file.AddEntry(@"myFolder1\myhtml1.html", "<div>This is Saad</div>");
这篇关于使用ionic.zip.zipfile创建目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!