Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I'm trying zip 100 000 dynamic files, and on console app i can do it without any problem, but on web app it appears that it's at some kind impossible for my current knowledge level. I would like to know is it really impossible ?

So far zip made on webapp that is bigger than 65535 files crashes on opening.

What I have tried:

I made this test apps but I wasn't able to find answer.

console

C#
static void Main(string[] args)
{
    using (ZipOutputStream zipOutputStream = new ZipOutputStream(File.Create("Test.zip")))
    {
        zipOutputStream.SetLevel(0);
        for (long i = 1; i < 100000; i++)
        {
            string txt = "File " + i.ToString();
            byte[] bytes = System.Text.Encoding.UTF8.GetBytes(txt);
            using (MemoryStream ms = new MemoryStream(bytes))
            {
                ZipEntry entry =
                    new ZipEntry(ZipEntry.CleanName(i.ToString() + ".txt"))
                    {
                        DateTime = DateTime.Now,
                        CompressionMethod = CompressionMethod.Stored,
                        Size = bytes.Length
                    };
                zipOutputStream.PutNextEntry(entry);
                byte[] buffer = new byte[1024];
                ICSharpCode.SharpZipLib.Core.StreamUtils.Copy(ms, zipOutputStream, buffer);
                Console.WriteLine(i.ToString());
            }
        }
    }
}


web

C#
protected void Page_Load(object sender, EventArgs e)
{
    Response.Clear();
    Response.ClearHeaders();
    Response.Cache.SetCacheability(HttpCacheability.NoCache);
    Response.ContentType = "application/octet-stream";
    Response.AddHeader("Content-Disposition", "attachment; filename=" + "file.zip");

    using (ZipOutputStream zipOutputStream = new ZipOutputStream(Response.OutputStream))
    {
        zipOutputStream.SetLevel(0);
        for (long i = 1; i < 100000; i++)
        {
            string txt = "File " + i.ToString();
            byte[] bytes = System.Text.Encoding.UTF8.GetBytes(txt);
            using (MemoryStream ms = new MemoryStream(bytes))
            {
                ZipEntry entry =
                    new ZipEntry(ZipEntry.CleanName(i.ToString() + ".txt"))
                    {
                        DateTime = DateTime.Now,
                        CompressionMethod = CompressionMethod.Stored,
                        Size = bytes.Length
                    };
                zipOutputStream.PutNextEntry(entry);
                byte[] buffer = new byte[1024];
                ICSharpCode.SharpZipLib.Core.StreamUtils.Copy(ms, zipOutputStream, buffer);
                Response.Flush();
            }
        }
    }
    Response.Flush();
    Response.End();
}
Posted
Updated 13-Apr-17 2:58am

1 solution

No, it isn't possible. That took me about 10 seconds to Google for.

Try DotNetZip instead.
 
Share this answer
 
Comments
Roszadok 18-Apr-17 0:59am    
It's also impossible.
Regards.
Dave Kreskowiak 18-Apr-17 10:01am    
Wow. Nice downvote for no reason at all. I said TRY it. I didn't say it would work.

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