A function to download file is given here.This is tested for asp.net 2.0 and working well.This will help many asp.net developers.
Private Sub FileDownload(ByVal strFileName As String, ByVal strFilePath As String)
Dim strRequest As String
strRequest = strFilePath & strFileName
If strRequest <> "" Then
Dim path As String = Server.MapPath(strRequest)
Dim file As System.IO.FileInfo = New System.IO.FileInfo(path)
If file.Exists Then
Response.Clear()
Response.AddHeader("Content-Disposition", "attachment; filename=" & file.Name)
Response.AddHeader("Content-Length", file.Length.ToString())
Response.ContentType = "application/octet-stream"
Response.WriteFile(file.FullName)
Response.End()
Else
Response.Write("This file does not exist.")
End If
Else
Response.Write("Please provide a file to download.")
End If
End Sub
5 Dec 2006
Subscribe to:
Post Comments (Atom)
1 comment:
Dim strFile As String
strFile = "Resume.doc"
Response.ContentType = "Application/octet-stream"
Response.AddHeader("Content-Disposition", "fileName=" + strFile)
Response.WriteFile(Server.MapPath("Files\\" + strFile))
Response.End()
Post a Comment