Click here to Skip to main content
15,895,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Updated 16-Feb-15 10:43am
v3
Comments
Richard Deeming 16-Feb-15 16:33pm    
Have you tried including the folder name in the file name parameter?
file.AddEntry("myFolder1/myhtml1.html", "<div>This is Saad</div>");
SaadZulfiqar 16-Feb-15 16:44pm    
Yes,i just tried it and it worked. Thanks Richard
Richard Deeming 16-Feb-15 16:45pm    
I'll post this as a solution to move your question out of the "unanswered" list. :)

1 solution

Include the folder name in the file name parameter:
C#
file.AddEntry("myFolder1/myhtml1.html", "<div>This is Saad</div>");

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:
C#
// 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>");
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900