Response.BinaryWrite Not Returning Result

  • Thread starter Thread starter Steve Harclerode
  • Start date Start date
S

Steve Harclerode

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.ContentType =
Convert.ToString(Session["DataContentType"]);
Response.AddHeader("Content-Disposition", "attachment;
filename=" +
Convert.ToString(Session["DataFileName"]));
Response.BinaryWrite(_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.ClearContent() and Response.ClearHeaders() 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?
 
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
 
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
 
Back
Top