Tuesday, February 28, 2012

Export to CSV

HttpContext.Current.Response.Clear()
HttpContext.Current.Response.Buffer =
TrueHttpContext.Current.Response.AddHeader(
HttpContext.Current.Response.Charset =
"content-disposition", "attachment;filename=GLAmountsExport.csv")""HttpContext.Current.Response.ContentType = "application/text"
dt = GetXRefDataPageWise()
Dim dt As DataTable' GridView1.AllowPaging = False' GridView1.DataBind()

sb.Append(dt.Columns(k).ColumnName +
Dim sb As New StringBuilder()For k As Integer = 0 To dt.Columns.Count - 1","c)Nextsb.Append(vbCr & vbLf)


sb.Append(dt.Rows(i)(k).ToString +
For i As Integer = 0 To dt.Rows.Count - 1For k As Integer = 0 To dt.Columns.Count - 1","c)Nextsb.Append(vbCr & vbLf)
NextHttpContext.Current.Response.Output.Write(sb.ToString())
HttpContext.Current.Response.Flush()
HttpContext.Current.Response.End()

Need to add  ","+c to display the values correctly in csv file .

No comments:

Post a Comment