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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Saber ShaikhPosted Apr 15, 2015, 6:30 AM
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
Harminder SinghPosted Apr 15, 2015, 3:49 AM
Harminder SinghPosted Apr 15, 2015, 3:36 AM
Saber ShaikhPosted Apr 15, 2015, 3:25 AM
Saber ShaikhPosted Apr 15, 2015, 3:21 AM
Use this
Manoj BhoirPosted Apr 15, 2015, 2:59 AM
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");
}
}
}
}
Harminder SinghPosted Apr 15, 2015, 2:56 AM
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();
Saber ShaikhPosted Apr 15, 2015, 2:33 AM
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