2

I have a CSV file of data which I'm attempting to use in my Windows Phone 7 application. I'm trying to figure out how to open and consume the data in my app. I've seen some examples around about using Linq to do this, but they use OleDB to open the CSV file.

Note: I want to deploy the data with my app, instead of using a Web Service, because it is cleaner and not that much data. If there is no coding way to do it, perhaps a way to convert to XML?

Mick N
  • 14,892
  • 2
  • 35
  • 41
pearcewg
  • 9,545
  • 21
  • 79
  • 125

2 Answers2

4

Nothing wrong with using light weight CSV input files.

You can use StreamReader.Readline to pull in a line at a time.

And String.Split to parse the comma seperated values into usable elements. For example:

string csv = "abc,123,def,456";
string[] elements = csv.Split(',');
foreach (string s in elements)
    System.Diagnostics.Debug.WriteLine(s);
Mick N
  • 14,892
  • 2
  • 35
  • 41
  • Wow, too easy. Should have realized that. You are an awesome knowledge, have answered a number of my questions. Thanks! – pearcewg Jan 13 '11 at 14:29
  • 1
    Just a note that using Split() on it's own isn't going to handle more complex csvs with double quotes properly :) – Henry C Feb 16 '12 at 11:58
0

Still no third-party library for CSV-parsing in Windows Phone apps at the time of this answer...

If you need to parse CSV with quotes, see this answer.

Community
  • 1
  • 1
Maxim Kamalov
  • 745
  • 9
  • 23