Get Application directory from console program
-
I am writing a C# console program that needs to read a file from the same directory as the application. I can't use the current directory as that is not the same as the application directory. Normally I would use Application.ExecutablePath, but console apps don't derive from Application. Ideas?
-
I am writing a C# console program that needs to read a file from the same directory as the application. I can't use the current directory as that is not the same as the application directory. Normally I would use Application.ExecutablePath, but console apps don't derive from Application. Ideas?
System.Reflection.Assembly execAsm = System.Reflection.Assembly.GetExecutingAssembly(); string asmPath = execAsm.CodeBase.Replace("file:///", "").Replace('/', '\\'); MessageBox.Show(asmPath);
-
System.Reflection.Assembly execAsm = System.Reflection.Assembly.GetExecutingAssembly(); string asmPath = execAsm.CodeBase.Replace("file:///", "").Replace('/', '\\'); MessageBox.Show(asmPath);
I'd just got to that point, but I'm using : System.Reflection.Assembly.GetExecutingAssembly().Location Thanks.
-
I am writing a C# console program that needs to read a file from the same directory as the application. I can't use the current directory as that is not the same as the application directory. Normally I would use Application.ExecutablePath, but console apps don't derive from Application. Ideas?
Application.ExecutablePath
works anyway, try it before you discard it. "We learn more from our mistakes than we do from getting it right the first time." -
I am writing a C# console program that needs to read a file from the same directory as the application. I can't use the current directory as that is not the same as the application directory. Normally I would use Application.ExecutablePath, but console apps don't derive from Application. Ideas?
That's easy, just use
AppDomain.CurrentDomain.BaseDirectory
to get the running directory and add to it your console application name and you have a path just like Application.ExecutablePath. -
I am writing a C# console program that needs to read a file from the same directory as the application. I can't use the current directory as that is not the same as the application directory. Normally I would use Application.ExecutablePath, but console apps don't derive from Application. Ideas?