G
Guest
Hi,
I'm trying to download a memorystream to a .csv file on the users desktop.
When I go to write out the memorystream through the byte array it seems to
truncate at 1024 and I don't know how to increase the size. Here is my code
if that helps.
Thanks.
Dim msw As MemoryStream = New MemoryStream
msw.SetLength(5000)
Dim sw As New StreamWriter(msw)
' First we will write the headers.
Try
Dim strBuffer As String = ""
Dim c As Integer
Dim dt As DataTable = CType(Session("GridData"), DataTable)
Dim iColCount As Integer = dt.Columns.Count
For c = 0 To iColCount - 1
strBuffer += dt.Columns(c).ToString
If (c < iColCount - 1) Then
strBuffer += ","
End If
Next
strBuffer += ControlChars.NewLine
' Now write all the rows.
Dim dr As DataRow
For Each dr In dt.Rows
For c = 0 To iColCount - 1
strBuffer += (dr(c).ToString)
If (c < iColCount - 1) Then
strBuffer += (",")
End If
Next
strBuffer += ControlChars.NewLine
Next
sw.Write(strBuffer)
Dim byteArray() As Byte = msw.ToArray()
msw.Flush()
msw.Close()
Response.Clear()
'Add Headers to enable dialog display
Response.AddHeader("Content-Disposition", "attachment;
filename=TownGrants.csv")
Response.AddHeader("Content-Length", byteArray.Length.ToString())
Response.ContentType = "application/octet-stream"
Response.BinaryWrite(byteArray)
Catch ex As Exception
End Try
I'm trying to download a memorystream to a .csv file on the users desktop.
When I go to write out the memorystream through the byte array it seems to
truncate at 1024 and I don't know how to increase the size. Here is my code
if that helps.
Thanks.
Dim msw As MemoryStream = New MemoryStream
msw.SetLength(5000)
Dim sw As New StreamWriter(msw)
' First we will write the headers.
Try
Dim strBuffer As String = ""
Dim c As Integer
Dim dt As DataTable = CType(Session("GridData"), DataTable)
Dim iColCount As Integer = dt.Columns.Count
For c = 0 To iColCount - 1
strBuffer += dt.Columns(c).ToString
If (c < iColCount - 1) Then
strBuffer += ","
End If
Next
strBuffer += ControlChars.NewLine
' Now write all the rows.
Dim dr As DataRow
For Each dr In dt.Rows
For c = 0 To iColCount - 1
strBuffer += (dr(c).ToString)
If (c < iColCount - 1) Then
strBuffer += (",")
End If
Next
strBuffer += ControlChars.NewLine
Next
sw.Write(strBuffer)
Dim byteArray() As Byte = msw.ToArray()
msw.Flush()
msw.Close()
Response.Clear()
'Add Headers to enable dialog display
Response.AddHeader("Content-Disposition", "attachment;
filename=TownGrants.csv")
Response.AddHeader("Content-Length", byteArray.Length.ToString())
Response.ContentType = "application/octet-stream"
Response.BinaryWrite(byteArray)
Catch ex As Exception
End Try