I publish a console project
in C#
and I put it in the path environment
FE c:\some\path\project.exe
. the excecutable has the following code.
Console.WriteLine(Environment.GetCommandLineArgs()[0]);
Console.WriteLine(System.AppContext.BaseDirectory);
Console.WriteLine(System.AppDomain.CurrentDomain.BaseDirectory);
Console.WriteLine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location));
Console.WriteLine(Path.GetDirectoryName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName));
When I execute it. in the cmd I Get the following:
c:\here\here\here > project.exe
c:\some\path\project.dll
c:\some\path\
c:\some\path\
c:\some\path
c:\some\path
I need to get the path c:\here\here\here
Try this: Console.WriteLine(Directory.GetCurrentDirectory());
You could do something like this besides what was suggested in Dharati's answer:
string fullPath = System.Reflection.Assembly.GetEntryAssembly().Location;
string noFileNamePath = fullPath.Substring(0, (fullPath.LastIndexOf('\\') + 1));
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.