I’m trying to make the app which is usually started by drag’n’dropping files on it to load the config file common to other apps, which resides in the parent directory of the app.
The problem is whenever I start the app by drag’n’dropping, @"..\config.cfg" beomes @"where\the\drag_n_dropped\file\is\..\config.cfg" and not the app’s own directory.
How do I fix it?
Answer:
string pathToThisApp =
System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)
and after getting the path we can extract the parent directory by using
pathToThisApp.Substring(0, pathToThisApp.LastIndexOf(@"\") + 1);
+ 1 is needed to keep the last \ sign in the path string.
Use Assembly.GetExecutingAssembly().Location