
I need some ASP C# code fixed. Potentially seconds of work if you know the answer.
- or -
Post a project like this2671
£50(approx. $67)
- Posted:
- Proposals: 4
- Remote
- #2022959
- PRE-FUNDED
- Awarded
Description
Experience Level: Intermediate
Estimated project duration: 1 day or less
I am trying to dynamically create huge zip files.
I get an error at "zo.Finish();" when the user tries to download zip files that are larger than 4.8GB. I need this code fixed so it can create ZIP files of potentially 100GB+. I cant buffer the downloadable file as it needs to start the download immediately.
I have tried running IIS as 64 bit but this has not resolved it.
The code I have is:
string path = @"C:\temp";
Response.Clear();
Response.ContentType = "application/zip";
Response.AddHeader("Content-Disposition", string.Format("attachment; filename=\"{0}\"", "hive.zip"));
Response.BufferOutput = false;
byte[] buffer = new byte[1024 * 1024];
using (ZipOutputStream zo = new ZipOutputStream(Response.OutputStream, 1024 * 1024))
{
zo.SetLevel(0);
zo.UseZip64 = ICSharpCode.SharpZipLib.Zip.UseZip64.On;
DirectoryInfo di = new DirectoryInfo(path);
foreach (string file in Directory.GetFiles(di.FullName, "*.*", SearchOption.AllDirectories))
{
string folder = Path.GetDirectoryName(file);
if (folder.Length > di.FullName.Length)
{
folder = folder.Substring(di.FullName.Length).Trim('\\') + @"\";
}
else
{
folder = string.Empty;
}
zo.PutNextEntry(new ZipEntry(folder + Path.GetFileName(file)));
//zo.UseZip64 = ICSharpCode.SharpZipLib.Zip.UseZip64.On;
using (FileStream fs = System.IO.File.OpenRead(file))
{
ICSharpCode.SharpZipLib.Core.StreamUtils.Copy(fs, zo, buffer);
}
//zo.CloseEntry();
zo.Flush();
Response.Flush();
}
zo.Finish(); // <---- THIS IS WHERE THE ERROR IS
//zo.IsStreamOwner = false;
//zo.Finish();
//zo.Close();
}
Response.Flush();
I get an error at "zo.Finish();" when the user tries to download zip files that are larger than 4.8GB. I need this code fixed so it can create ZIP files of potentially 100GB+. I cant buffer the downloadable file as it needs to start the download immediately.
I have tried running IIS as 64 bit but this has not resolved it.
The code I have is:
string path = @"C:\temp";
Response.Clear();
Response.ContentType = "application/zip";
Response.AddHeader("Content-Disposition", string.Format("attachment; filename=\"{0}\"", "hive.zip"));
Response.BufferOutput = false;
byte[] buffer = new byte[1024 * 1024];
using (ZipOutputStream zo = new ZipOutputStream(Response.OutputStream, 1024 * 1024))
{
zo.SetLevel(0);
zo.UseZip64 = ICSharpCode.SharpZipLib.Zip.UseZip64.On;
DirectoryInfo di = new DirectoryInfo(path);
foreach (string file in Directory.GetFiles(di.FullName, "*.*", SearchOption.AllDirectories))
{
string folder = Path.GetDirectoryName(file);
if (folder.Length > di.FullName.Length)
{
folder = folder.Substring(di.FullName.Length).Trim('\\') + @"\";
}
else
{
folder = string.Empty;
}
zo.PutNextEntry(new ZipEntry(folder + Path.GetFileName(file)));
//zo.UseZip64 = ICSharpCode.SharpZipLib.Zip.UseZip64.On;
using (FileStream fs = System.IO.File.OpenRead(file))
{
ICSharpCode.SharpZipLib.Core.StreamUtils.Copy(fs, zo, buffer);
}
//zo.CloseEntry();
zo.Flush();
Response.Flush();
}
zo.Finish(); // <---- THIS IS WHERE THE ERROR IS
//zo.IsStreamOwner = false;
//zo.Finish();
//zo.Close();
}
Response.Flush();

Christopher V.
100% (9)Projects Completed
10
Freelancers worked with
10
Projects awarded
63%
Last project
18 Apr 2025
United Kingdom
New Proposal
Login to your account and send a proposal now to get this project.
Log inClarification Board Ask a Question
-
Hi Christopher!
What kind of exception do you have?
Dmitry
648222
We collect cookies to enable the proper functioning and security of our website, and to enhance your experience. By clicking on 'Accept All Cookies', you consent to the use of these cookies. You can change your 'Cookies Settings' at any time. For more information, please read ourCookie Policy
Cookie Settings
Accept All Cookies