Content-disposition question

A

Alex Nitulescu

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
 
A

Alex Nitulescu

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
 

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,967
Messages
2,570,148
Members
46,694
Latest member
LetaCadwal

Latest Threads

Top