How to create Zip files in Asp.Net? -



How to create Zip files in Asp.Net? -

in asp.net 2.0, need take multiple folders along files. our requirement take folders , need create single zip file. can help me on this.

thanks.

download sharpziplib, it's 1 of more popular zip libraries add reference icsharpcode.sharpziplib.dll

you can go through code samples when download sharpziplib sense of how can zip , unzip files, here's example:

public static void main(string[] args) { zipfiles("d:\\sharpzip","d:\\zipped.zip"); } private static void zipfiles(string inputdirectory, string outputdirectory) { if (directory.exists(inputdirectory)) { string[] filenames = directory.getfiles(inputdirectory); using (zipoutputstream zipstream = new zipoutputstream(file.create(outputdirectory))) { zipstream.setlevel(9); byte[] buffer = new byte[4096]; foreach (string file in filenames) { zipentry entry = new zipentry(path.getfilename(file)); entry.datetime = datetime.now; zipstream.putnextentry(entry); using (filestream fs = file.openread(file)) { int sourcebytes; { sourcebytes = fs.read(buffer, 0, buffer.length); zipstream.write(buffer, 0, sourcebytes); } while (sourcebytes > 0); } } zipstream.finish(); zipstream.close(); } } }

asp.net

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -