WP7 - read from CSV file? Or what to do with the data? - c#

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?

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);

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.

Related

What are the ways to analyse(scan and find) data from single or multiple csv files using C# or any other language?

I am in the process of developing application in C# which analyse multiple files .csv files using some sort of queries or functions and it display results.
So far, I have managed to create application which opens .csv file using excel but I have just found that Microsoft Excel won't read record of more than 104,000. In my case I have record of 705.000. So currently I am converting those .csv files in Microsoft Access database and from that using queries I have populated those results into my C# application.
However, this process is long and I have to convert all the files into Access and then I can analyse the data. Is there any other way I can directly read multiple .csv files and filter what I am looking for?
Any suggestions or help will be appreciated.
Thanks,
Harsh Panchal
Depending upon what your analysis needs are you might find R with the ff package to be a useful tool.
If you really must use c# for this task then is there some reason you cannot simply read the files one line at a time analyzing as you go?
You can try this. Untested.
//Read all lines into array in once.
var tmparray = File.ReadAllLines("C:\YourFile.csv");
for (var i = 0; i < tmparray.Length; i += 1)
{
//Assuming ";" is your seperator. (or delimiter)
subArray=tmparray[i].Split(';');
//Do anything with your subArray.
}

Google Api FreeBase data dumps parsing using c#

I want to search the google Api freebase. I want to get general amount of data. For example all Ids of songs, or films. I downloaded the data dumps gz file. I wonder what will be the best solution of parsing the file and getting the data I need. I am using .net c#.
There are a couple .NET libraries that can read the RDF format of the dumps:
SemWeb.NET
dotNetRdf
The data dumps are also formatted as tab separated values so you should be able to use any CSV parser to parse each line as a triple.
Make sure that you read through the developer docs on how the data dumps are formatted. Basically, each line forms a triple that has a subject, predicate and object. To get all the data about films you'll be looking for triples that have a predicate that starts with /film/.

wp7 quickly localizing a ton of strings in app

I have an app where I am trying to localize about 100 strings into 15+ languages. When it comes to using resx in visual studio, I can only copy/paste into one cell at a time. Naturally, I don't want to have to do this 1500 times.
Is there a way/program where I can use to take all my translated strings, and just copy/paste them into the entire cell column, one time each for the 15+ languages I have?
I tried Resex, but at face value it doesn't look like I can do that? Maybe I am just using it wrong?
Thank you!
If you can get it a CSV file (e.g: export from Excel) I have a simple tool to convert the CSV to a RESX file: http://lostintranslation.apphb.com/ (select CSV to bundle and .NET)

How to format and read this kind of CSV file in C#

Here is just an example of the data I need to read from csv file.
How get the first row as a name of the all columns?
How to parse this data?
(I will use the data to draw a graphs)
Year;I1;I2;I3;II1;III2 2012;2.4;3.1;1.2;3.7;0.8
2007;-1.1;-5.1;-2.5;-0.8;0.6 2001;3.9;4.4;1.8;2.4;5.9
Thanks for all who helped me, i solved my problem, thanks ;)
I suggest using a specialized library for this - FileHelpers is a popular third party choice:
The FileHelpers are a free and easy to use .NET library to import/export data from fixed length or delimited records in files, strings or streams.
If you must use Microsoft libraries, TextFieldParser in the Microsoft.VisualBasic.FileIO namespace can also be used:
Provides methods and properties for parsing structured text files.
You'll want to read the file line by line, and use String.Split to split it up by ';' into an array.
How to: Read a Text File One Line at a Time (Visual C#)
Another free tool is the CSV Reader. No Need to invent the wheel over and over again ;)

How can I automatically retrieve a CSV file from web, save it in a directory, and access it in C#?

I am working on an application which has to retrieve data from a CSV file online
and display it with a click of a button. However, how can I automatically store
the CSV file in a safe place where I can access the information? I am working with Visual Studio C#.
Thank you.
You want to use the WebClient class to make an http request to the server for the csv file. It should read the whole contents as a string which you can then parse and manipulate at your leisure.
http://msdn.microsoft.com/en-us/library/system.net.webclient(VS.100).aspx
Use System.IO.File to write the contents to a file.
http://msdn.microsoft.com/en-us/library/system.io.file.aspx
The FileHelpers are a free and easy to use .NET library to import/export data from fixed length or delimited records in files, strings or streams.
The FileHelpers Library
http://www.filehelpers.com/

Categories