Re: download a file problem
Response.Clear() before you AppendHeader(). Look at this sample code and compare it with what you've got.
http://www.vbforums.com/showpost.php...78&postcount=2
Besides, if you just want them to download it, send it as an octet stream. Does the type then matter?
Re: download a file problem
it doesnt work sorry using a download manager.
when i download a file my 3rd part download manager comes up and downloads the file from the URL (which is the actual aspx file that downloads and NOT the file I require which is set in that file revision3.doc).
now if i click cancel then a second screen appears which is the normal download screen and it correctly downloads the revision3.doc.
Now I need this fixed for security reasons.
Code:
Dim fullpath As String
Dim name As String
Dim type As String = ""
Dim ext As String
Dim forceDownload As Boolean
name = "revision3.doc"
forceDownload = True
ext = ".doc"
fullpath = "f:\asp\" + name
' Dim ext2 = Path.GetExtension(fullpath)
'TextBox1.Text = ext2.ToString
Dim FilePath As String = fullpath
Dim TargetFile As New FileInfo(FilePath)
If Not IsDBNull(ext) Then
ext = LCase(ext)
End If
Select Case ext
Case ".htm", ".html"
type = "text/HTML"
Case ".txt"
type = "text/plain"
Case ".doc", ".rtf"
type = "Application/msword"
Case ".csv", ".xls"
type = "Application/x-msexcel"
Case Else
type = "text/plain"
End Select
If (forceDownload) Then
Response.Clear()
Response.AppendHeader("content-disposition", _
"attachment; filename=" + TargetFile.Name)
Response.AddHeader("Content-Length", TargetFile.Length.ToString())
End If
If type <> "" Then
' Response.ContentType = type
Response.ContentType = "application/octet-stream"
End If
Response.WriteFile(TargetFile.FullName)
Response.End()
Re: download a file problem
What else are you doing on the page? Does it have any HTML/aspx content?
Re: download a file problem
the code i gave is all in the button click and there is nothing else in that button click code. .
Protected Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click
in the page (design area)i have a few asp buttons and 1 textbox.
note php has the same problem until i tweaked a few commands
do you mean i cant use an asp button for this?
Re: download a file problem
Can the third party downloader do a button click? No. It has no way of knowing that you want the download to happen on the button click.
Therefore, you need to put the download in a separate, standalone page without any markup (HTML/ASPX) in it. Just do it on the page load, based upon querystring parameters if you need.
Re: download a file problem
ok when i run a page with any content i cant simply overwrite the headers with code for a download manager .
i am not exactly sure how this works but it seems any content written to the screen before a download sets the variables which the download manager picks up.
Re: download a file problem
Yes, hence the need for a standalone page. Treat the page in the browser as you would with the third party downloader, the browser itself is a download tool of sorts. If you have to 'do' something on the page to get the download working, then the third party downloader will need to do the same. Hence, you need a response.redirect which takes you to the real download page.