unwanted HTML in tab-delimited file export

  • Thread starter Thread starter DC Gringo
  • Start date Start date
D

DC Gringo

I am outputting a datatable to a tab-delimited file. This all works well
and good with 2 issues:

1) There is some data in my table that looks like this:
<a_tag>theData</a_tag>. I would like to be able to strip out the tags
before writing to the csv file

2) If there are 100 rows output, then the 102nd row has the HTML of the
..aspx webform that contains the button which calls the
tab-delimitedf-ile-writing function. How can I get rid of this? Here's my
code:

Public Sub btnCommunitiesExcel_OnClick(ByVal sender As System.Object, ByVal
e As System.EventArgs)
Dim ds As New DataSet
Dim da As New SqlDataAdapter(Session("savedCommunitiesSql"),
connection1.conString)
da.Fill(ds, "CommunitiesExcel")
Dim dt As DataTable = ds.Tables("CommunitiesExcel")
Response.ContentType = "application/ms-excel"
Response.AddHeader("Content-Disposition", "inline;filename=test.csv")
Response.Write(ConvertDtToTDF(dt))
End Sub


Private Function ConvertDtToTDF(ByVal dt As DataTable) As String

Dim dr As DataRow, ary() As Object, i As Integer
Dim iCol As Integer

'Output Column Headers
For iCol = 0 To dt.Columns.Count - 1
Response.Write(dt.Columns(iCol).ToString & vbTab)
Next

Response.Write(vbCrLf)

'Output Data
For Each dr In dt.Rows
ary = dr.ItemArray
For i = 0 To UBound(ary)
Response.Write(ary(i).ToString & vbTab)
Next
Response.Write(vbCrLf)
Next
End Function
 
Before the Response.Write, try putting a Response.Clear()
and After the Response.Write, try putting a Response.End().
 
Back
Top