Tuesday, April 22, 2008

How to open filedialog in web applications

call below function when u need to open dialog box
DisplayDownloadDialog("MyDown.doc")
----------------------------------------------------------
Sub DisplayDownloadDialog(ByVal PathVirtual As String)

Dim strPhysicalPath As String
Dim objFileInfo As System.IO.FileInfo
Try
strPhysicalPath = Server.MapPath(PathVirtual)
'exit if file does not exist
If Not System.IO.File.Exists(strPhysicalPath) Then Exit Sub
objFileInfo = New System.IO.FileInfo(strPhysicalPath)
Response.Clear()
'Add Headers to enable dialog display
Response.AddHeader("Content-Disposition", "attachment; filename=" & objFileInfo.Name)
Response.AddHeader("Content-Length", objFileInfo.Length.ToString())

Response.ContentType = "application/octet-stream"
Response.WriteFile(objFileInfo.FullName)


Catch
'on exception take no action
'you can implement differently
Finally

Response.End()

End Try
End Sub

No comments:

Loading...