public static void CreateCSVFile(DataSet myData, string strFileName, string strReportTitle) { HttpContext.Current.Response.Clear(); HttpContext.Current.Response.Buffer = true; HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=" + strFileName + ".csv"); HttpContext.Current.Response.Charset = string.Empty; HttpContext.Current.Response.ContentType = "application/text"; StringBuilder sb = new StringBuilder(); DataTable dt = myData.Tables[0]; for (int k = 0; k < dt.Columns.Count; k++) { sb.Append(dt.Columns[k].ColumnName + ','); } sb.Append("\r\n"); for (int i = 0; i < dt.Rows.Count; i++) { for (int k = 0; k < dt.Columns.Count; k++) { sb.Append(dt.Rows[i][k].ToString().Replace(",", ";") + ','); } sb.Append("\r\n"); } HttpContext.Current.Response.Output.Write(sb.ToString()); HttpContext.Current.Response.Flush(); HttpContext.Current.Response.End(); }
dt.Columns["digit_column"].DataType = typeof(System.String);
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)