Adding a CSV file as a resource file and accessing it in code

I have a .csv file that I will read using the oledb method in my code. Now I want this CSV file to be my resource file, so I added this file to the resources. But a structure with access to the resource file from the code, can someone please help me with this

thank

+3
source share
1 answer

Assuming your CSV file is embedded as a resource, you can access it as follows:

using (var stream = Assembly
    .GetExecutingAssembly()
    .GetManifestResourceStream("YourNamespace.test.csv"))
using (var reader = new StreamReader(stream))
{
    string csv = reader.ReadToEnd();
    // do something with the CSV
}
+9
source

Source: https://habr.com/ru/post/1735577/


All Articles