Click here to Skip to main content
14,868,570 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()
VB
sb.Append("<table width='100%' border='1' class='data' cellspacing='0' cellpadding='0'>")
sb.Append("<tr>")

'''''''
'''''

'''''
''''''
VB
sb.Append("</tr>")
sb.Append("</table>")
dvReport.InnerHtml = sb.ToString()

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

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

dvReport.RenderControl(htmlWrite)
Response.Write(stringWrite.ToString())


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.
Posted
Updated 31-Mar-15 22:01pm
v2

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: http://en.wikipedia.org/wiki/Comma-separated_values[^]
   

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