Displaying File name on a fetcher page

R

Rukmal Fernando

Hi all,

I have a file retrieved from a database and I want to return it over a web
page.

I currently have an ASPX page (Download.aspx) with code similar to the
following in Page_Load():

...
string file = Request["file"];byte[] fileData = this.getFile(file); // this
fetches the file's data, to be writtenResponse.ContentType =
"application/octet-stream"
Response.AppendHeader("Content-Disposition", "filename=" & file);
Response.AppendHeader("Content-Length",
fileData.Length);Response.BinaryWrite(file);Response.Flush();...I can invoke
this as http://localhost/FetchFile/Download.aspx?file=MyFile.docThis code
works perfectly and returns the file with a download prompt.The problem that
I do have, is that the page shows it's own filename as the title.While this
is not an issue for download links, this page is also indexed, and the
results display a meaningless "Download.aspx" as the result.Adding
"Response.Write("<TITLE>" + file + "</TITLE");also doesn't work, as it gets
mixed up with the file contents, and basically corrupts it.I also tried
setting the page as the default page for the site, so files can be
downloaded ashttp://localhost/FetchFile/?file=MyFile.doc, but then it
returns "FetchFile" as the title.Is there a way of forcing the page's title
to be something I want?I'd appreciate any insight on this.Thanks in
advance,Rukmal.
 
J

John Saunders

Rukmal Fernando said:
Hi all,

I have a file retrieved from a database and I want to return it over a web
page.

I currently have an ASPX page (Download.aspx) with code similar to the
following in Page_Load():

...
string file = Request["file"];byte[] fileData = this.getFile(file); // this
fetches the file's data, to be writtenResponse.ContentType =
"application/octet-stream"
Response.AppendHeader("Content-Disposition", "filename=" & file);
Response.AppendHeader("Content-Length",
fileData.Length);Response.BinaryWrite(file);Response.Flush();...I can invoke
this as http://localhost/FetchFile/Download.aspx?file=MyFile.docThis code
works perfectly and returns the file with a download prompt.The problem that
I do have, is that the page shows it's own filename as the title.While this
is not an issue for download links, this page is also indexed, and the
results display a meaningless "Download.aspx" as the result.Adding
"Response.Write("<TITLE>" + file + "</TITLE");also doesn't work, as it gets
mixed up with the file contents, and basically corrupts it.I also tried
setting the page as the default page for the site, so files can be
downloaded ashttp://localhost/FetchFile/?file=MyFile.doc, but then it
returns "FetchFile" as the title.Is there a way of forcing the page's title
to be something I want?I'd appreciate any insight on this.Thanks in
advance,Rukmal.

What happens if you use:

Content-Disposition: attachment; filename=<file>

?
 

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,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top