473,383 Members | 1,925 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Content-disposition question

Hi. First of all, I *HAVE* to express my annoyance with how badly (at least)
this content thing is documented in MSDN. There's no head, nor tail to it.

Anyway, I have this code in a form named "Download.aspx". There's all there
is to it - no UI, nothing else. This is all the code.
__________________________________________________ _________
'Retrieve the path of the file to download, and create a FileInfo object to
read its properties
Dim strPath As String = Server.MapPath(Request.Params("File"))
Dim objFileInfo As FileInfo = New FileInfo(strPath)

'Clear the current output content from the buffer
Response.Clear()

'Add the header that specifies the default filename for the Download/SaveAs
dialog
Response.AddHeader("Content-Disposition", "attachment filename=" &
objFileInfo.Name)

'Add the header that specifies the file size, so that the browser can show
the download progress
Response.AddHeader("Content-Length", objFileInfo.Length.ToString())

'Specify that the response is a stream that cannot be read by the client and
must be downloaded
Response.ContentType = "application/octet-stream"

'Send the file stream to the client
Response.WriteFile(objFileInfo.FullName)

'Stop the execution of this page
Response.End()
__________________________________________________ _________

In another form I have for instance this anchor: <a
href="Download.aspx?File=/aspnetprojects/vsnet/ThePhile/Old.txt">

As you can see, I'm passing to Download.aspx the file Old.txt. However, the
dialog box shows the filename as being "Download.aspx" instead. Still, if I
press okay, the *CORRECT* file is downloaded, only with the wrong name
(Download.aspx instead of Old.txt). I checked my code in debug, and
objFileInfo is perfect. What can I do ? Is this a known bug ? I searched on
the net and I haven't found any fix or any bug report concerning this
behaviour.

I have IE6 with the latest and greatest updates, and XPSP2.

Thank you,
Alex
Nov 19 '05 #1
1 1459
Please disregard this message - I found the reason - I was missing a ";"
after the word "attachment"

Instead of
Response.AddHeader("Content-Disposition", "attachment filename=" &
objFileInfo.Name)

now I have
Response.AddHeader("Content-Disposition", "attachment; filename=" &
objFileInfo.Name)

and it works.

Thanks !
Alex

"Alex Nitulescu" <RE***********************@yahoo.com> wrote in message
news:uH**************@TK2MSFTNGP10.phx.gbl...
Hi. First of all, I *HAVE* to express my annoyance with how badly (at
least) this content thing is documented in MSDN. There's no head, nor tail
to it.

Anyway, I have this code in a form named "Download.aspx". There's all
there is to it - no UI, nothing else. This is all the code.
__________________________________________________ _________
'Retrieve the path of the file to download, and create a FileInfo object
to read its properties
Dim strPath As String = Server.MapPath(Request.Params("File"))
Dim objFileInfo As FileInfo = New FileInfo(strPath)

'Clear the current output content from the buffer
Response.Clear()

'Add the header that specifies the default filename for the
Download/SaveAs dialog
Response.AddHeader("Content-Disposition", "attachment filename=" &
objFileInfo.Name)

'Add the header that specifies the file size, so that the browser can show
the download progress
Response.AddHeader("Content-Length", objFileInfo.Length.ToString())

'Specify that the response is a stream that cannot be read by the client
and must be downloaded
Response.ContentType = "application/octet-stream"

'Send the file stream to the client
Response.WriteFile(objFileInfo.FullName)

'Stop the execution of this page
Response.End()
__________________________________________________ _________

In another form I have for instance this anchor: <a
href="Download.aspx?File=/aspnetprojects/vsnet/ThePhile/Old.txt">

As you can see, I'm passing to Download.aspx the file Old.txt. However,
the dialog box shows the filename as being "Download.aspx" instead. Still,
if I press okay, the *CORRECT* file is downloaded, only with the wrong
name (Download.aspx instead of Old.txt). I checked my code in debug, and
objFileInfo is perfect. What can I do ? Is this a known bug ? I searched
on the net and I haven't found any fix or any bug report concerning this
behaviour.

I have IE6 with the latest and greatest updates, and XPSP2.

Thank you,
Alex

Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: jonathan.beckett | last post by:
Hi All, For the past few months I have been working on an open source Apache/PHP/MySQL content management system - and have recently made it available for download. It's still very much a...
0
by: jonathan.beckett | last post by:
Hi All, I have just made version 0.4.8 of the PluggedOut CMS Content Management System available for download - it's free, and covered by the GPL. It's still very much a work in progress...
0
by: Scott Abel | last post by:
For immediate release: The Rockley Group Content Management Workshop Series Coming to Atlanta, Seattle, Vancouver, Chicago, Washington, DC, Toronto, and Research Triangle Park Learn more:...
14
by: j1c | last post by:
How can I remove the content in between tags? I have a page that has several custom tags: <!--tag:1--> Content 1 <!--/tag:1--> <br> <!--tag:2--> Content 2 <!--/tag:2--> <br> <!--tag:3--> Content 3...
1
by: Richard | last post by:
http://dynamicdrive.com/dynamicindex5/linkinfo.htm Using the above script, I have a plan whereby when the main link is active, two different content swaps take place. Column A shows the main...
10
by: clintonG | last post by:
Can somebody direct me to documents or source that supports the use of collapsible content that is collapsed by default when the page is loaded? The secondary objective would of course be...
7
by: xkeops | last post by:
Thinking of creating a website, most of the pages will have a general toolbar menu, a content and a footer. The content will be the only one who's gonna change but the rest (header,footer) will...
0
by: Managed Code | last post by:
Hello All, Here is my issue and thanks in advance for any assistance. I have a base page with a dropdownlist that fires an event with the selected index. The content page catches the event and...
1
by: dave8421 | last post by:
Hi, I'm trying to make sense of the definition for "Rendered Content" in current CR for CSS 2.1 Is rendered content what is displayed on the particular media or device? from the...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.