Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding .csv file as resource file and accessing it in the code

Tags:

c#

I have a .csv file which i will read using oledb method in my code now i want this .csv file as my resource file so i have added that file in the resources. But struct with accessing the resource file from the code, can anyone please help me on this

Thanks

like image 889
Sathish Avatar asked Dec 29 '22 00:12

Sathish


1 Answers

Assuming that your CSV file is embedded as a resource you could access it like this:

using (var stream = Assembly
    .GetExecutingAssembly()
    .GetManifestResourceStream("YourNamespace.test.csv"))
using (var reader = new StreamReader(stream))
{
    string csv = reader.ReadToEnd();
    // do something with the CSV
}
like image 154
Darin Dimitrov Avatar answered Jan 03 '23 17:01

Darin Dimitrov