private void OnExportGridToCSV(object sender, System.EventArgs e) { // Create the CSV file to which grid data will be exported. StreamWriter sw = new StreamWriter(Server.MapPath("~/GridData.txt"), false); // First we will write the headers. DataTable dt = m_dsProducts.Tables[0]; 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])) { sw.Write(dr[i].ToString()); } if ( i < iColCount - 1) { sw.Write(","); } } sw.Write(sw.NewLine); } sw.Close(); }
and to import... refer to link
http://forums.asp.net/t/1208600.aspx hope this help let me know in both cases
if(my-Post ==Helpful){ Marked as Answered }
else
{return "need more help"}
None
0 Points
3 Posts
Import and export of a csv
May 09, 2010 06:25 AM|Drastixnz|LINK
I have a csv file and I want to be able to open it remove two colums and save it back as a cvs by clicking on one button....
I am now banging my head against the well trying to get it working any help would be great,
All-Star
194009 Points
28027 Posts
Moderator
Re: Import and export of a csv
May 09, 2010 10:00 AM|Mikesdotnetting|LINK
You could try something like this: http://mikehadlow.blogspot.com/2008/06/linq-to-csv.html
Contributor
7260 Points
1902 Posts
Re: Import and export of a csv
May 11, 2010 06:32 AM|nareshguree23@gmail.com|LINK
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=4132&lngWId=10
check it
Member
411 Points
290 Posts
Re: Import and export of a csv
May 11, 2010 06:47 AM|usmi123|LINK
for export use this..
else
{return "need more help"}