Response.BinaryWrite Not Returning Result

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Steve Harclerode

    Response.BinaryWrite Not Returning Result

    Hi all,

    I have a web application that uploads a file into a SQL database as a stream
    of bytes.

    On another page of the app, I retrieve the same byte stream from SQL, and my
    ultimate goal is for the user to see the "save" dialog so that they can
    download it as a file on their own computer.

    I'm using this C# code to return the result to the user:
    Response.Clear( );
    Response.Conten tType =
    Convert.ToStrin g(Session["DataContentTyp e"]);
    Response.AddHea der("Content-Disposition", "attachment ;
    filename=" +
    Convert.ToStrin g(Session["DataFileNa me"]));
    Response.Binary Write(_ibuffer) ;

    If I set a breakpoint in this code, I see that there is a web page in my
    browser that is waiting for the code to complete. However, as soon as I
    choose Continue in the debugger, the browser window closes, and there is no
    dialog asking me to save the file.

    Here's what I've tried:
    - calling Response.ClearC ontent() and Response.ClearH eaders() in the
    beginning
    - putting in a call to Response.End() at the end
    - changing "attachment " above to "inline"

    The first 2 options gave the same result (the browser window closes). The
    3rd option allowed me to view content for "known" file types such as JPG in
    the browser, but for unknown file types, the browser window still closed.

    Any ideas?

    --
    My BizTalk blog:
    A place for me to store and share some notes about technical stuff I'm working with at the moment. The views expressed on this blog are mine alone and do not necessarily reflect the views of my employer.



  • Steve Harclerode

    #2
    Re: Response.Binary Write Not Returning Result

    I solved my own problem -- when I used "localhost" as the server name in the
    browser URL, it behaves as below. When I replace it with the actual server
    name, it works the way I want it to.

    - Steve

    "Steve Harclerode" <Lizard.That.Wa s@hot.mail.comw rote in message
    news:ude0R0xfIH A.1660@TK2MSFTN GP02.phx.gbl...
    Hi all,
    browser that is waiting for the code to complete. However, as soon as I
    choose Continue in the debugger, the browser window closes, and there is
    no dialog asking me to save the file.

    Comment

    • Steve Harclerode

      #3
      Re: Response.Binary Write Not Returning Result

      In case someone else runs into this problem:

      I discovered that localhost was listed in the trusted servers. When I
      removed it from the list, now I can use localhost in the URL. Why that would
      cause a problem is beyond me, but there it is...

      - Steve

      "Steve Harclerode" <Lizard.That.Wa s@hot.mail.comw rote in message
      news:OGv3i7xfIH A.5180@TK2MSFTN GP05.phx.gbl...
      >I solved my own problem -- when I used "localhost" as the server name in
      >the browser URL, it behaves as below. When I replace it with the actual
      >server name, it works the way I want it to.
      >
      - Steve
      >
      "Steve Harclerode" <Lizard.That.Wa s@hot.mail.comw rote in message
      news:ude0R0xfIH A.1660@TK2MSFTN GP02.phx.gbl...
      >Hi all,
      >browser that is waiting for the code to complete. However, as soon as I
      >choose Continue in the debugger, the browser window closes, and there is
      >no dialog asking me to save the file.
      >
      >

      Comment

      Working...