Add this Namespaces
Imports System.Configuration
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports System.IO
Write this Code where you want
Dim Path As String = Server.MapPath("SendRequest\" + Filename)
Dim FileInfor As New FileInfo(Path)
Dim stringWriter As New StringWriter()
Dim htmlWrite As New HtmlTextWriter(stringWriter)
Dim directory__1 As String = Path.Substring(0, Path.LastIndexOf("\"))
If Not Directory.Exists(directory__1) Then
Directory.CreateDirectory(directory__1)
End If
Dim vw As New System.IO.StreamWriter(Path, True)
stringWriter.ToString().Normalize()
vw.Write(stringWriter.ToString())
vw.Flush()
vw.Close()
WriteAttachment(FileInfor.Name, "application/vnd.ms-excel", stringWriter.ToString())
Add this Function also
Public Shared Sub WriteAttachment(ByVal FileName As String, ByVal FileType As String, ByVal content As String)
Dim Response As HttpResponse = System.Web.HttpContext.Current.Response
Response.ClearHeaders()
Response.AppendHeader("Content-Disposition", "attachment; filename=" & FileName)
Response.ContentType = FileType
Response.Write(content)
Response.[End]()
End Sub