Appending Data to End of CSV File

10 views
Skip to first unread message

evan...@gmail.com

unread,
May 23, 2008, 1:33:50 PM5/23/08
to CSVChat
Hello

Thank you for your great product.

I'm exporting data from a DataTable in a Web page to a .csv file. I
need to append a footer containing a copyright to the bottom of the
csv file. Is there to do this using the WriteAll method on this line?

writer.WriteAll(myDataTable, True)

Maybe I can add this to the DataTable itself?




Private Sub ExcelExport(ByVal sender As System.Object, ByVal e As
System.EventArgs)
Dim SqlText As String
SqlText = lblSqlText.Text

Dim MyConnection As SqlConnection

MyConnection = New
SqlConnection(ConfigurationSettings.AppSettings("CorpLibConnectionStringCurr"))
Dim MyAdapter As New SqlDataAdapter(SqlText, MyConnection)

Dim myDataTable As DataTable = New DataTable()
MyAdapter.Fill(myDataTable)

Try
MyConnection.Open()
Response.Clear()
Response.ClearHeaders()
Dim writer As New CsvWriter(Response.OutputStream, ","c,
Encoding.Default)
writer.WriteAll(myDataTable, True)
writer.Close()

Dim FileDate As String = Replace(FormatDateTime(Now(),
DateFormat.ShortDate), "/", "")
Response.AddHeader("Content-Disposition",
"attachment;filename=CompanySearchResults_" & FileDate & ".csv")
Response.ContentType = "application/vnd.ms-excel"
Response.End()
Finally
'close the connections
End Try

End Sub

evan...@gmail.com

unread,
May 23, 2008, 2:36:55 PM5/23/08
to CSVChat
I was able to add a new row to my DataTable which seems to work.
Thanks.


On May 23, 1:33 pm, "evanbu...@gmail.com" <evanbu...@gmail.com> wrote:
> Hello
>
> Thank you for your great product.
>
> I'm exporting data from a DataTable in a Web page to a .csv file.  I
> need to append a footer containing a copyright to the bottom of the
> csv file. Is there to do this using the WriteAll method on this line?
>
> writer.WriteAll(myDataTable, True)
>
> Maybe I can add this to the DataTable itself?
>
> Private Sub ExcelExport(ByVal sender As System.Object, ByVal e As
> System.EventArgs)
>         Dim SqlText As String
>         SqlText = lblSqlText.Text
>
>         Dim MyConnection As SqlConnection
>
>         MyConnection = New
> SqlConnection(ConfigurationSettings.AppSettings("CorpLibConnectionStringCur­r"))

shriop

unread,
May 23, 2008, 8:27:54 PM5/23/08
to CSVChat
Glad to hear you got it solved. Sorry for the late response. There
were several ways that you could go about it. If yours worked, then it
was probably the easiest. You could have also just executed a
writer.Write("Copyright goes here") and a writer.EndRecord() after the
WriteAll. You could have also have attached a StreamWriter to
Response.OutputStream to call a .Write without csv escaping once
writer.Flush has been called after the WriteAll.

Bruce Dunwiddie
> >     End Sub- Hide quoted text -
>
> - Show quoted text -
Reply all
Reply to author
Forward
0 new messages