Script(s)

what I learn is what u c

Asp.net (vb) write to Memory Stream

leave a comment »

    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

Advertisements

Written by gchandra

May 3, 2005 at 1:24 pm

Posted in Web Coding

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: