Not able to invoke download dialog
Hi everybody,
I am trying to invoke the download dialog using the following code:
VB Code:
Private Sub nMaintenanceBackup_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles nMaintenanceBackup.Click
Try
DisplayDownloadDialog("KSIL2005.BAK")
Catch vException As Exception
Session("vErrorMessage") = vException.ToString
Response.Redirect(cErrorPageURL & "True")
End Try
End Sub
Private Function DisplayDownloadDialog(ByVal vdownload_file As String) As String
Dim objFileInfo As System.IO.FileInfo
Try
objFileInfo = New System.IO.FileInfo(vdownload_file)
Response.Clear()
'Add Headers to enable dialog display
Response.ContentType = "application/octet-stream"
Response.AddHeader("Content-Disposition", "attachment; filename=" & _
objFileInfo.Name)
'Response.AddHeader("Content-Length", objFileInfo.Length.ToString())
Response.Flush()
Response.WriteFile(objFileInfo.FullName)
Catch
Finally
Response.End()
End Try
End Function
This code works perfectly fine on my computer which has Windows 2000 Professional SP4. However, when I run it on my client's computers (hosted in the same computer) which have Windows XP Professional and Windows 2000 Advanced Server, it shows up the download dialog for Default.aspx which is the web page where the above code is present. Following are the contents of the download dialog:
---------------------------------------------------------------------------------------
You are downloading the file: Default.aspx from localhost
Would you like to open the file or save it to your computer?
Open Save Cancel More Info
---------------------------------------------------------------------------------------
What could be the problem? What is the solution?