Downloading file from database

J

Jeremy Chapman

I have build a web page that lists files in a database. When the user
clicks on the file the page streams the file contents to the browser with
code like:
Response.AppendHeader("Content-Disposition","attachment;filename=" +
strFileName);
Response.AppendHeader("Content-Length",lLength.ToString());
Response.ContentType = strContentType;
Response.BinaryWrite(binData);

My problem is that if the file is html or xml, it appears in the browser
window. If the file is jpg, text, etc it appears in a seperate application
window. The desired behaviour is to always show the document in a seperate
window, but I can't write specific code to handle each file type
individually. Is it possible to force the file to download a view in a
seperate window?
 
E

Edwin Knoppert

Just the correct content type.
I enforce downloading PDF instead of viewing it this way.
 
J

Jeremy Chapman

The type is correct. But for some types windows displays them using IE, and
in that case it displays it in the same window as the list of files. If
it's in IE, I want it to display in a seperate window.
 
E

Edwin Knoppert

Oh, i meant it the other way around, by NOT using the real type like pdf but
that inary, you get the download fialog.
But now i see you don't want that.
You might consider to open an new window and point to the pdf.
But i don't think you'll be able to determine if the pdf get's loaded IN the
window or not.

So, leave it to the user..
 
C

Casper Stendal

Hi Jeremy

You just have to put your page stream code in a seperate file, and then link
to that file with window.open() or target="_blank", when everything should
work just like you want... ;)

/Stendal
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top