I have 3 application (asp.net website, console application, SSIS) and a common class library which is used by all these 3 application. That common library fetch the external configuration file which is located in the the current running directory. For example
ASP.NET - > c:\MySite\appconfig.xml
CONSOLE -> C:\MyConsoleApplication\appconfig.xml
SSIS -> c:\MySSISPakage\appconfig.xml
I used the following code to fetch the current running application path to fetch the appconfig.xml file
string appPath = AppDomain.CurrentDomain.BaseDirectory;
In the web application it is running file and returning the path
c:\MySite.
But in the console application it is return the path
C:\MyConsoleApplication\bin\debug
. I need to fetch the path
C:\MyConsoleApplication
for the console application. Any idea?
You can Find Parent Directory using Directory.GetParent
try like this: Program
is name of any class in your project
string path = Path.GetDirectoryName(Assembly.GetAssembly(typeof(Program)).Location);
Console.WriteLine(Directory.GetParent(Directory.GetParent(path).ToString()).ToString());
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.