Download file and a "dead window"

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • nino.altran@gmail.com

    Download file and a "dead window"

    In an aspx page there is the possibility to download a file. I don't
    want to give the user a direct link, so I wrote the following code:

    .....
    try
    {
    byte[] buff = System.IO.File. ReadAllBytes(pa th);
    int filesize = buff.Length;

    Response.ClearH eaders();
    Response.AddHea der("Content-type", ContentType);
    Response.AddHea der("Content-Disposition", "attachment ;
    filename=\"" + filename + "\"");
    Response.Output Stream.Write(bu ff, 0, filesize);
    Response.Output Stream.Flush();
    }
    catch
    { .....

    I have a problem:
    - If I put this code in my page, when the postback is executed the
    download starts, but the page "dies" (the postback doesn't render
    again my page)
    - If I put this code in a new page, loaded in a popup, the download
    starts but the popup "dies" (I can't write anything in it and I don't
    know how I can close it automatically)

    Can someone help me? Thank you in advance!
  • Hans Kesting

    #2
    Re: Download file and a "dead window"

    nino.altran@gma il.com formulated the question :
    In an aspx page there is the possibility to download a file. I don't
    want to give the user a direct link, so I wrote the following code:
    >
    .....
    try
    {
    byte[] buff = System.IO.File. ReadAllBytes(pa th);
    int filesize = buff.Length;
    >
    Response.ClearH eaders();
    Response.AddHea der("Content-type", ContentType);
    Response.AddHea der("Content-Disposition", "attachment ;
    filename=\"" + filename + "\"");
    Response.Output Stream.Write(bu ff, 0, filesize);
    Response.Output Stream.Flush();
    }
    catch
    { .....
    >
    I have a problem:
    - If I put this code in my page, when the postback is executed the
    download starts, but the page "dies" (the postback doesn't render
    again my page)
    - If I put this code in a new page, loaded in a popup, the download
    starts but the popup "dies" (I can't write anything in it and I don't
    know how I can close it automatically)
    >
    Can someone help me? Thank you in advance!
    You might need a Response.Clear( ).
    I always end these kind of codeblocks with a Response.End() and have no
    problem with "dead" pages.

    Note: there is also a Response.WriteF ile(path) which doesn't need to
    buffer the entire file.

    Hans Kesting


    Comment

    • nino.altran@gmail.com

      #3
      Re: Download file and a "dead window"

      Thank you for your answer, unfortunately my page keeps not working...
      but I found a trick to kill the "dead window" with javascript. Thank
      you again!

      Comment

      • Patrice

        #4
        Re: Download file and a "dead window"

        You may want to double check this to solve the problem rather than to cure
        its consequences.

        AFAIK this is when you actually send something (generally I'm using a link
        to a download page). Knowing how it is triggered could help so that we can
        try to repro this behavior (if opening a window using js rather than a
        link)...

        --
        Patrice

        <nino.altran@gm ail.coma écrit dans le message de groupe de discussion :
        34514115-6acb-4a69-b3dc-b9310a2d9927...le groups.com...
        Thank you for your answer, unfortunately my page keeps not working...
        but I found a trick to kill the "dead window" with javascript. Thank
        you again!

        Comment

        Working...