0

I've been working on an assignment for college which involves reading in some variables from a CSV file. I've completed my code and have everything working.

When referring the the CSV file I use a line of code similar to the foloowing:

File.ReadAllLines(@"C:\Users\FILE\LOCATION\ON\DISK\FILE.CSV")

The only problem is that when i submit my code to be graded, obviously when who ever is marking the code tries to compile and run it will be greeted with an unhandled exception.

Can I place the CSV somewhere in the project folder and refer to it with a relative path (as can me done in HTML)?

I've tried using answers to similar questions on this site, but I'm pretty new to programming and don't understand some of the answers.

Thanks!

Dylan
  • 1
  • 3

1 Answers1

2

You can put your csv file into your solution folder as content and select Copy to Output Directory as always.

then call your code

File.ReadAllLines(@"FILE.CSV");

enter image description here

Derviş Kayımbaşıoğlu
  • 28,492
  • 4
  • 50
  • 72
  • I would use right click solution in Solution Explorer. Select Add -> Exisitng Item. Then choose your file. The proceed as Simonare answer. – Mary Dec 16 '18 at 19:57
  • https://stackoverflow.com/questions/3259583/how-to-get-files-in-a-relative-path-in-c-sharp?noredirect=1&lq=1 will help you more – Manish Jain Dec 16 '18 at 20:15