Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

222
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda