unwanted HTML in tab-delimited file export

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
 
S

Steve C. Orr [MVP, MCSD]

Before the Response.Write, try putting a Response.Clear()
and After the Response.Write, try putting a Response.End().
 
D

DC Gringo

Steve,

Ok, that worked!!

And what about getting rid of my <strong> tags?

_____
Glenn
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top