private static void CreateCSVFile(DataTable dt, string strFilePath, string webServerFileLink) { // Create the CSV file to which grid data will be exported. StreamWriter sw = new StreamWriter(strFilePath, false); // First we will write the headers. int iColCount = dt.Columns.Count; for (int i = 0; i < iColCount; i++) { sw.Write(dt.Columns[i]); if (i < iColCount - 1) { sw.Write(","); } } sw.Write(sw.NewLine); // Now write all the rows. foreach (DataRow dr in dt.Rows) { for (int i = 0; i < iColCount; i++) { if ((!Convert.IsDBNull(dr[i])) && (i == 7)) { sw.Write(dr[i].ToString().Replace("\r", " ")); } else { sw.Write(dr[i].ToString().Replace(",", " ")); } if (i < iColCount - 1) { sw.Write(","); } } sw.Write(sw.NewLine); } sw.Close(); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)