Skip to content

Instantly share code, notes, and snippets.

@FlameWert
Created February 8, 2020 01:28
Show Gist options
  • Save FlameWert/0f777e6ff078103c3fe211f7c80fb9d2 to your computer and use it in GitHub Desktop.
Save FlameWert/0f777e6ff078103c3fe211f7c80fb9d2 to your computer and use it in GitHub Desktop.
Various ways to get location of an exe file of a C# app

If running program via Task Scheduler

string path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);

Other Ways

string path = System.IO.Path.GetDirectoryName(Application.ExecutablePath);

sring path = Application.StartupPath`

string path = System.IO.Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment