C# - How to Zip file on the Web Server?
-
Salut everyone, i have done lotz of seaching but i haven't find much. Anyhelp is greatly appreciate. I export a report into a csv file onto the webserver folder, now what i would like to do is zip that file that i just saved and allow the user to download it when they click a button. Anyone know what class .NET support for zipping a file? or any sample code on C# is great because i'm stuck here. merci beaucoup :);) *HyVong*
-
Salut everyone, i have done lotz of seaching but i haven't find much. Anyhelp is greatly appreciate. I export a report into a csv file onto the webserver folder, now what i would like to do is zip that file that i just saved and allow the user to download it when they click a button. Anyone know what class .NET support for zipping a file? or any sample code on C# is great because i'm stuck here. merci beaucoup :);) *HyVong*
-
Salut everyone, i have done lotz of seaching but i haven't find much. Anyhelp is greatly appreciate. I export a report into a csv file onto the webserver folder, now what i would like to do is zip that file that i just saved and allow the user to download it when they click a button. Anyone know what class .NET support for zipping a file? or any sample code on C# is great because i'm stuck here. merci beaucoup :);) *HyVong*
-
Salut everyone, i have done lotz of seaching but i haven't find much. Anyhelp is greatly appreciate. I export a report into a csv file onto the webserver folder, now what i would like to do is zip that file that i just saved and allow the user to download it when they click a button. Anyone know what class .NET support for zipping a file? or any sample code on C# is great because i'm stuck here. merci beaucoup :);) *HyVong*
I have discussed this topic in this forum before, but check out #ziplib[^], it should do what you are looking for. - Nick Parker
My Blog | My Articles -
The ZIP classes in the J# runtime assemblies have problems where they don't create the right ZIP format all the time. Read Bug when using the java.util.zip classes to write zip files[^] for more information and links.
Software Design Engineer Developer Division Sustained Engineering, Microsoft My Articles
-
The ZIP classes in the J# runtime assemblies have problems where they don't create the right ZIP format all the time. Read Bug when using the java.util.zip classes to write zip files[^] for more information and links.
Software Design Engineer Developer Division Sustained Engineering, Microsoft My Articles
using java.util.zip; using java.io; .. .. i created method to zip the file based on the codes have given.
private void ZipFile(string fileName, string ExpType) { string extType = "zip"; string zipFileName = fileName + "." + extType; string soureFileName = fileName + "." + ExpType; // Output stream // ONCE IT RUNS THIS LINE, IT GIVES ME THE ERROR // SAYS 'ACCESS IS DENIED.' FileOutputStream fos = new FileOutputStream(zipFileName); // Tie to zip stream ZipOutputStream zos = new ZipOutputStream(fos); // Stream with source file FileInputStream fis = new FileInputStream(soureFileName); // It's our entry in zip ZipEntry ze = new ZipEntry(soureFileName); zos.putNextEntry(ze); sbyte[] buffer = new sbyte[1024]; int len; // Read and write until done while((len = fis.read(buffer)) >= 0) { zos.write(buffer, 0, len); } // Close everything zos.closeEntry(); fis.close(); zos.close(); fos.close(); }
I have the folder that held the file temporary has full access for users. I don't know if i have to give the path for it to be able to zip too? Please help, i have no clue why it says access is denied. And is the code above correct? I haven't had a chance to test the whole codes since the first line had some error. hope to hear from everyone soon. thank you so much.:( *HyVong* oh and when i tried to delete the file after it's being zipped, but i can't, 'File' is an ambiguous reference, how do i delete the file after being zipped? File.Delete(Server.MapPath(@"~\import\\" + soureFileName)); Thanx so much for all your help. -
using java.util.zip; using java.io; .. .. i created method to zip the file based on the codes have given.
private void ZipFile(string fileName, string ExpType) { string extType = "zip"; string zipFileName = fileName + "." + extType; string soureFileName = fileName + "." + ExpType; // Output stream // ONCE IT RUNS THIS LINE, IT GIVES ME THE ERROR // SAYS 'ACCESS IS DENIED.' FileOutputStream fos = new FileOutputStream(zipFileName); // Tie to zip stream ZipOutputStream zos = new ZipOutputStream(fos); // Stream with source file FileInputStream fis = new FileInputStream(soureFileName); // It's our entry in zip ZipEntry ze = new ZipEntry(soureFileName); zos.putNextEntry(ze); sbyte[] buffer = new sbyte[1024]; int len; // Read and write until done while((len = fis.read(buffer)) >= 0) { zos.write(buffer, 0, len); } // Close everything zos.closeEntry(); fis.close(); zos.close(); fos.close(); }
I have the folder that held the file temporary has full access for users. I don't know if i have to give the path for it to be able to zip too? Please help, i have no clue why it says access is denied. And is the code above correct? I haven't had a chance to test the whole codes since the first line had some error. hope to hear from everyone soon. thank you so much.:( *HyVong* oh and when i tried to delete the file after it's being zipped, but i can't, 'File' is an ambiguous reference, how do i delete the file after being zipped? File.Delete(Server.MapPath(@"~\import\\" + soureFileName)); Thanx so much for all your help.actually i got this work, thank you so much for all your help i changed to
System.IO.File.Delete(Server.MapPath(@"~\import\\" + soureFileName));
and the file did got zip, i gave it a path for specific folder// Stream with source file
FileInputStream fis = new FileInputStream(Server.MapPath(@"~\import\\" + soureFileName));
// Output stream
FileOutputStream fos = new FileOutputStream(Server.MapPath(@"~\import\\" + zipFileName));
// Tie to zip stream
ZipOutputStream zos = new ZipOutputStream(fos);once again, thank you for all your help :) *HyVong*
-
Salut everyone, i have done lotz of seaching but i haven't find much. Anyhelp is greatly appreciate. I export a report into a csv file onto the webserver folder, now what i would like to do is zip that file that i just saved and allow the user to download it when they click a button. Anyone know what class .NET support for zipping a file? or any sample code on C# is great because i'm stuck here. merci beaucoup :);) *HyVong*