Answer the question
In order to leave comments, you need to log in
What is the correct way to change from an absolute path to a relative path in C#?
Hello.
I use an absolute path in all my code:
How to change the path correctly so that the xml file is next to the exe?
There are solutions on the Internet, but to do so - all for some reason controversial
THANKS
string filename = @"c:\Users\1\source\test.xml";
Answer the question
In order to leave comments, you need to log in
What is the correct way to change the path so that the xml file is next to the exe?first change the task in your head (what is the cause? and what is the effect?)
.\bin\Debug\
in this case, the relative path to such a file will be something like ..\..\
Several options to choose from depending on the type of your project:
https://stackoverflow.com/questions/6041332/best-w...
Write the path to the config and use it as the base one. There will be fewer surprises, especially if you are not allowed to write to the folder next to the binary.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question