Reputation: 948
I have a program that can edit a certain text file. Currently, I am only running it in Visual Studios. When I am referring to the text file, the file path looks something like this:
@"C:\myProjectFolder\someTextFile.txt"
For now, I can use this path and it works flawlessly, but after I deploy it, the program would only work on my computer because this path is specific to my computer.
In HTML for example, if I was linking a CSS file, it would be possible to do \stylesheets\style.css
instead of C:\myWebsite\stylesheets\style.css
How can I achieve something similar in C#
Upvotes: 0
Views: 81
Reputation: 1071
Use System.Windows.Forms.Application.StartupPath and Application.executablePath
for getting current application path.
if file is in current directory of .Exe
file full path is not required and just name of file is enough. you also can point to current path in some situations by ".\\"
Upvotes: 1