question

RAgibNoor-5332 avatar image
0 Votes"
RAgibNoor-5332 asked WenyanZhang-MSFT commented

Efficient way to read large csv file in c#

In xamarin ios application When i am trying to read a large csv file applications crash. the code works fine for smaller csv file .
What will be the most efficient way to read csv file and store into datatable

dotnet-xamarin
· 7
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Are you sure this is a Xamarin question? It is probably a C# question.

Regardless, you will need to be more specific than crash. What is the error code and/or error message? If you can post the relevant code then that will help.

0 Votes 0 ·

DataTable dataTable = new DataTable();
using (var csv = new DelimitedRecordReader(new StreamReader(filePath, Encoding.UTF8),20))
{
csv.ReadColumnHeaders();
dataTable .Load(csv); // application crash here . app close automatically
}

II am using https://github.com/slorion/nlight this library to read the csv file. The above code works fine for large csv file in .net application on mac/windows but in ios device its not working for large csv (I guess its due to limited resources of mobile device) .

0 Votes 0 ·

There is a link about reading csv file, it got a list finally. You could store the list into database by using SQLite. I am afraid your app crash is not caused by the large size of file. The SQLite .NET library that Xamarin recommends is a basic ORM that lets you store and retrieve objects in the local SQLite database on an iOS device
In addition, may I ask what the size of your file is? Would you mind sharing crash logs?





0 Votes 0 ·

csv file size is around 230Mb and there is 1500000 rows in it .
could you please enlighten me how can i get the crash log for the application

0 Votes 0 ·

Do you install the app in your own iPhone? Or install the app in Simulator? You can get the logs by the following steps if you install the app in your own iPhone.
1. Connect the device with XCode
2. Open XCode, click "Window", select"Devices and Simulators"
3. Click "View Device Logs"
If you use the Simulator, you can get the logs from output view, you can also make a break point to check.

1 Vote 1 ·
Show more comments

0 Answers