I have written in my console application a line System.IO.Path.GetFullPath("ApplicationSubDirectory") to get application directory file system path.
I build this application and installed exe in my system. exe has been installed in c://ProgramFiles/AppFolder/ directory. When I execute exe then I got valid path like c://ProgramFiles/AppFolder/ApplicationSubDirectory.
But when i scheduled this exe to run dailly basis in windows scheduler. Then I am getting wrong path. This returns me path of directory where windows scheduler is installed like c://Windows/System32/ApplicationSubDirectory. This is wrong path.
Please help me how i get valid path after scheduling exe too.
Thanks a lot.
解决方案
This is because your console application is started by the Task Scheduler. To obtain the actual path add the following code to your application
System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);