Search code examples
visual-studio-2017

Adding a CSV file to a project in Visual Studio


I am working on a project where I have to read in serveral pre-existing CSV (dog.csv, horse.csv, etc.). I want to know how would I add these file into my project so that I may test to see if my print functions work (the code is written in c++). Would I have to copy and paste the files into the debugging folder or would I place it under the test folder of the project?


Solution

  • You can include the files in your project in whatever (sub)folder you wish by using Right click -> Add -> Existing Item. Then, right-click on each file and choose Properties. Set up "Copy to output directory" to "Copy if newer".

    Then after build, your files will be copied into the bin/debug folder.

    To read the file, you can just use:

    System.IO.File.ReadAllText("dog.csv");