I have this little code:
HttpContext.Current.Response.Clear();
if ( files.Contains( ',' ) ) {
HttpContext.Current.Response.ContentType = "application/zip";
HttpContext.Current.Response.AddHeader( "content-disposition", "filename=arch-01.zip");
string[] split = files.Split( ',' );
ZipForge zip = new ZipForge();
try {
zip.FileName = Path.Combine( @"C:\Item", "arch-01.zip");
zip.OpenArchive( System.IO.FileMode.Create );
zip.BaseDir = @"C:\";
foreach ( string file in split ) {
zip.AddFiles( file );
}
zip.CloseArchive();
} catch ( Exception e ) {
Console.Write( e.Message );
}
}
I want after compressing to show Open - Save As dialog in browser. The files exists, we assume that files contains
C:\Item\a1.xls,C:\Item\a2.xls.
But the archive is empty, always. where is my mistakes ? I have permission on C:.
I something wrong at Response header ?
Problem solved
I have added following code:
HttpContext.Current.Response.WriteFile( zip.FileName );
and now works 🙂
I would try splitting out your issues out to figure out where the problem is. Make a console app that zips the files you are wanting to zip and see if that works. After that see if you can download the zip that you created and zip correctly works while downloading it from your asp.net website. There seems to be two things going on in the code which is fine but we need to determine where the actual problem is.