❔ Where to place files so my program can always find them?

Hey guys, I was working on one of my machines and my program is working fine. It has to open a csv file in a specific directory, and it does. But when I run it in visual studio, instead of looking in the root directory for the project, where all the files are, it looks "bin/Debug/netcoreapp6.0". How can I build my program so that these files are always in a set directory no matter the environment?
10 Replies
Monsieur Wholesome
Hardcode an absolute path and not a relative one
string myPath = "C:\Users\BlaBla\Desktop\myFile.csv";
string myPath = "C:\Users\BlaBla\Desktop\myFile.csv";
instead of
string myPath = "myFile.csv";
string myPath = "myFile.csv";
Kinda thing
Zesty "JFK" Sudol Questman
the issue I have is that my software should be completely portable so hard coding a path is not a possibility i think
Chiyoko_S
Chiyoko_S2y ago
place them in somewhere like %AppData%? but if you need it to be portable I think your best bet is to make it look from relative path tbh your problem could be solved trivially by just copying the said required file to output on build
Chiyoko_S
Chiyoko_S2y ago
yeah something like that works too. Basically very similar to what I've suggested, which is %AppData%
Pobiega
Pobiega2y ago
but yeah, if this is just a static csv that is shipped with your program, slap it in the "copy to output" will %appdata% work on linux?
Chiyoko_S
Chiyoko_S2y ago
who cares about linux
Pobiega
Pobiega2y ago
😄
Zesty "JFK" Sudol Questman
thx guys that was helpful ill look into the options i have
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server