Get full path of executing assembly

- Posted in Coding by

C# code to get the full path of the executing assembly:

<script src="https://gist.github.com/kyrathasoft/825c2c277bdaed4d300880415f72ab5b.js"></script>

then there's also this:

<script src="https://gist.github.com/kyrathasoft/4f4f1d6639c6faff0b2e4c77e60ede87.js"></script>

using System;
using System.Reflection; //required for Assembly namespace
using System.IO; //required for Path namespace

namespace HelloWorld {
class Hello {

    static void Main(string[] args){
        Console.WriteLine("n Now executing: {0}", ExecutingAssemblyPath());
        Console.Write("n Press any key to exit... ");
        Console.ReadKey();
        Console.WriteLine();
    }

    public static string ExecutingAssemblyPath(){
    string path = AppDomain.CurrentDomain.BaseDirectory;
    string fname = Assembly.GetEntryAssembly().GetName().Name;
    path += fname;
    if(File.Exists(fname + ".exe")){ path += ".exe"; } else {path += ".dll"; }
        return path;
    }    

  }
}