imports System.Io
imports System.Text
Sub Download
Dim mstream As New MemoryStream()
lxmlDoc.LoadXml(ldstOutPut.GetXml)
mstream = Generatefile()
‘
Dim bytearray() As Byte
bytearray = mstream.ToArray
mstream.Flush()
mstream.Close()
Response.Clear()
‘ Add a HTTP header to the output stream that specifies the default filename for the browser’s download dialog
Response.AddHeader(“Content-Disposition”, “attachment; filename=anyfilename.csv”)
‘ Add a HTTP header to the output stream that contains the
‘ content length(File Size). This lets the browser know how much data is being transfered
Response.AddHeader(“Content-Length”, bytearray.Length.ToString())
‘ Set the HTTP MIME type of the output stream
Response.ContentType = “application/xls”
‘ Other content types are “application/rtf” / “application/zip”
‘ Write the data out to the client.
Response.BinaryWrite(bytearray)
Response.Flush()
Response.Close()
End Sub
Private Function Generatefile() As MemoryStream
Dim fstClientLetter As MemoryStream
fstClientLetter = New MemoryStream()
Dim sw As New StreamWriter(fstClientLetter)
lstrOutput = “blah blah blah generate any content here”
sw.Write(lstrOutPut)
sw.Flush()
sw.Close()
Return fstClientLetter
End Function