By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,393 Members | 1,405 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,393 IT Pros & Developers. It's quick & easy.

Parse a CSV file in C#?

P: n/a
C
Hi,

I have a CSV file with some data (7,500 rows , 18 columns)

How can I parse this file in C#?

Can I programmatically save the file as an Excel Workbook and then parse the
file using the Excel Namespace Methods available?

Or can I programmatically save the CSV file as an XML file and then parse
the XML?

Any advice is much appreciated.

Thanks.
Apr 21 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a

Open with a StreamReader, read each line, then do a String.Split on the
commas. Repeat for each line.

"C" <C@discussions.microsoft.com> wrote in message
news:FA**********************************@microsof t.com...
Hi,

I have a CSV file with some data (7,500 rows , 18 columns)

How can I parse this file in C#?

Can I programmatically save the file as an Excel Workbook and then parse
the
file using the Excel Namespace Methods available?

Or can I programmatically save the CSV file as an XML file and then parse
the XML?

Any advice is much appreciated.

Thanks.

Apr 21 '06 #2

P: n/a
You can try the parser that I sell just for these situations,
http://www.csvreader.com .

Bruce Dunwiddie

Peter Rilling wrote:
Open with a StreamReader, read each line, then do a String.Split on the
commas. Repeat for each line.

"C" <C@discussions.microsoft.com> wrote in message
news:FA**********************************@microsof t.com...
Hi,

I have a CSV file with some data (7,500 rows , 18 columns)

How can I parse this file in C#?

Can I programmatically save the file as an Excel Workbook and then parse
the
file using the Excel Namespace Methods available?

Or can I programmatically save the CSV file as an XML file and then parse
the XML?

Any advice is much appreciated.

Thanks.


Apr 21 '06 #3

P: n/a

I have the code to "save as xml" at my blog:

If you have sql server (back end db) , then I also have a stored procedure
to use the excel.xml.

http://spaces.msn.com/sholliday/ 9/22/2005 entry


"C" <C@discussions.microsoft.com> wrote in message
news:FA**********************************@microsof t.com...
Hi,

I have a CSV file with some data (7,500 rows , 18 columns)

How can I parse this file in C#?

Can I programmatically save the file as an Excel Workbook and then parse the file using the Excel Namespace Methods available?

Or can I programmatically save the CSV file as an XML file and then parse
the XML?

Any advice is much appreciated.

Thanks.

Apr 21 '06 #4

P: n/a
> Open with a StreamReader, read each line, then do a String.Split on the
commas. Repeat for each line.


That doesn't work for all CSV files, though. The data in a data row may
contain line breaks, so a data row may span over any number of lines.

Fields that contain line breaks are generally enclosed in quotes. A quoted
field may also contain double quotes to represent quotes in the data.

Sadly there exists no independent standard for the CSV file format. Most CSV
files are not even comma separated at all, but semicolon separated.

The format that Microsoft Office uses seems to be a de-facto standard, but
as it's not a real standard, your CSV files may actually look rather
differently.
Apr 21 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.