Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

215
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda