how to create CSV file having multiple comma's in single column?
e.g.
id,description
101,abc,def
102,ghj
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Saber ShaikhRank #1,686 · 905 reputationPosted Apr 14, 2015, 10:33 PM EDT
string[] arr = { "one", "two", "three" }; // "string" can be lowercase.
Console.WriteLine(string.Join(",", arr)); // ... "String" can be uppercase.
Console.WriteLine(String.Join(",", arr));
Output
one,two,three
one,two,three
My blog
Harminder SinghRank #1,153 · 1.6K reputationPosted Apr 14, 2015, 10:56 PM EDT
Response.Clear();
Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment;filename=DATA.csv");
Response.Charset = "";
Response.ContentType = "application/text";
StringBuilder sbldr = new StringBuilder();
if (dt.Columns.Count != 0)
{
foreach (DataColumn col in dt.Columns)
{
sbldr.Append(col.ColumnName + ',');
}
sbldr.Append("\r\n");
foreach (DataRow row1 in dt.Rows)
{
foreach (DataColumn column in dt.Columns)
{
sbldr.Append(row1[column].ToString().Replace(',',' ') + ',');
}
sbldr.Append("\r\n");
}
}
Response.Output.Write(sbldr.ToString());
Response.Flush();
Response.End();
Manoj BhoirRank #599 · 4K reputationPosted Apr 14, 2015, 10:59 PM EDT
Check this sample code :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
using (StreamWriter sw = File.CreateText("d:\\TestCSV.csv"))
{
sw.WriteLine("1, 2, 3");
sw.WriteLine("4, 5, 6");
sw.WriteLine("\"7, 8\", 9 , 10");
}
}
}
}
Saber ShaikhRank #1,686 · 905 reputationPosted Apr 14, 2015, 11:21 PM EDT
Use this
Saber ShaikhRank #1,686 · 905 reputationPosted Apr 14, 2015, 11:25 PM EDT
Harminder SinghRank #1,153 · 1.6K reputationPosted Apr 14, 2015, 11:36 PM EDT
Harminder SinghRank #1,153 · 1.6K reputationPosted Apr 14, 2015, 11:49 PM EDT
Saber ShaikhRank #1,686 · 905 reputationPosted Apr 15, 2015, 2:30 AM EDT
Like
then use this Code only datatable Export
http://www.aspsnippets.com/Articles/Export-data-from-SQL-Server-to-Excel-in-ASPNet-using-C-and-VBNet.aspx