Search code examples
c#filepathstreamreader

How to avoid including full path to file


I've got a .csv-file that I've included in my project. I've created a StreamReader that takes a path as parameter, but I have to include the full path to the file instead of just the file name.

I.e. new StreamReader("products.csv"); instead of

new StreamReader(@"C:\Users\user\Documents\Visual Studio 2015\Projects\Solution\Project\Products\products.csv");

What can I do to make the StreamReader accept just a filename instead of a whole path?


Solution

  • You can move the file into your bin\debug folder and use this:

    new StreamReader("products.csv");