I'm fairly new to C#
. I've got a small project that makes use of a CSV
file. I want the user of the said little app to be able to place the CSV
file in the same folder as the startup file (or the .application file) and the program to be able to find it. I tried using the Application.StartupPath
but that led me to a different file path than the one I was hoping for.
Currently, when I publish my project, I've got my 'setup.exe', 'Floyds.application' and 'Application Files' all sitting in 'C:\Users\Dell\Desktop\Floyds Published'. This is where I'd ideally like to be able to place my CSV
file such that the app reads it. (Of course, this is just an example in my specific case, I'd like the little folder with those three to be the place where you can place CSV
files regardless of where it is.)
Alternatively, if anyone can give me another means of getting a simple relative file path that would make is easy enough for someone who doesn't know their way around computers too well to easily dump the file in a folder and for my program to be able to read it, that would also work.
string filepath;
if(FileAddressBox.Text == "")
{
filepath = Application.StartupPath + @"\InitialTable.csv";
}
else
{
filepath = FileAddressBox.Text;
}
using (var reader = new StreamReader(filepath))
Thanks in advance!
Edit: I should have probably clarified that it is a winforms application. My apologies!
Edit 2: I am ideally hoping that the user of the app swaps the CSV file with other CSV files regularly to get different results when running the application, so as to save the user from having to input the different CSVs filepath manually.
Edit 3: The link I was given to the other question does not seem to work either. Added the code where it is used.