Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

214
Views
Detect the end of download stream on browser with jquery function

I have implemented a function in an .NET application to download a large number of files using a stream with an undefined initial length. I need to capture, on the browser, when the stream ends to show an alert to the user but I have difficulty understanding how to solve or which workaround to use.

This is my function:

private void OutputStreamZipped(Page page)
    {

        page.Response.ContentType = "application/zip";
        page.Response.AddHeader("content-disposition", "attachment" + ";filename=" + "myFileName.zip");
        page.Response.AddHeader("Accept-Ranges", "bytes");
        page.Response.AddHeader("Expires", "0");
        page.Response.AddHeader("Pragma", "cache");
        page.Response.AddHeader("Cache-Control", "private");


        page.Response.Buffer = false;
        page.Response.BufferOutput = false;


        byte[] buffer = new byte[2 * 1024 * 1024];
        try
        {
            using (ZipOutputStream zipOutputStream = new ZipOutputStream(Response.OutputStream))
            {
                zipOutputStream.SetLevel(3);

                DirectoryInfo DI = new DirectoryInfo(@"C:\myFolder");
                foreach (var i in DI.GetFiles())
                {
                    Stream fs = File.OpenRead(i.FullName);
                    ZipEntry zipEntry = new ZipEntry(ZipEntry.CleanName(i.Name));
                    zipEntry.Size = fs.Length;
                    zipOutputStream.PutNextEntry(zipEntry);
                    int count = fs.Read(buffer, 0, buffer.Length);
                    while (count > 0)
                    {
                        zipOutputStream.Write(buffer, 0, count);
                        count = fs.Read(buffer, 0, buffer.Length);
                        if (!Response.IsClientConnected)
                        {
                            break;
                        }
                        Response.Flush();
                    }
                    fs.Close();
                }
                zipOutputStream.Close();
            }
            Response.Flush();


            page.Response.SuppressContent = true;

            System.Web.HttpContext.Current.ApplicationInstance.CompleteRequest();

        }
        catch (Exception)
        {
            throw;
        }
    }

Thanks to anyone who can give me a tip

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!