Click here to Skip to main content
15,346,368 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have to export the content of a div to csv file. My code is like below:

Dim sb As StringBuilder = New StringBuilder()
sb.Append("<table width='100%' border='1' class='data' cellspacing='0' cellpadding='0'>")


dvReport.InnerHtml = sb.ToString()

Dim stringWrite As System.IO.StringWriter = New System.IO.StringWriter()
Dim htmlWrite As System.Web.UI.HtmlTextWriter = New HtmlTextWriter(stringWrite)

Response.AddHeader("content-disposition", "attachment;filename=ReportFullDump.csv")
Response.Charset = ""
Response.ContentType = "application/CSV"


However i am not getting the desired output. output contains all the html tags in it.
Please suggest some solution with code examples.
Thanks in advance.
Updated 31-Mar-15 22:01pm

1 solution

Why would you have to export the contents of a div when you're the one building the div? Export from wherever the data comes in the first place. And why are you wondering about html tags in the output when you are obviously writing them yourself into the output/StringBuilder? And you have skipped the part of your code where you are supposedly writing the actual data. So the best answer is: Look up how a CSV file is suppose to look like and write it like that to your StringBuilder:[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900