2

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.

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
Shoeb
  • 652
  • 9
  • 17

2 Answers2

5

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);
Patrick D'Souza
  • 3,491
  • 2
  • 22
  • 39
2

The scheduler sets the current directory to the path mentioned above. System.IO.Path.GetFullPath("ApplicationSubDirectory") uses the current directory.

You could try AppDomain.CurrentDomain.BaseDirectory instead.