How to know the physical path of executing .Net assembly

In some cases you may come to a point where you want to know the physical path on your hard drive for the current assembly.. For example you might want to know the physical path of an Configuration XML file, which you already know that this file should be located on the same folder as the your assemblies. The following pecice of code show how u can know the path of your executing assembly

string executingAssemblyPath = "";

FileInfo file = new FileInfo(System.Reflection.Assembly.GetExecutingAssembly().Location);

executingAssemblyPath = file.DirectoryName;

Leave a Reply

Your email address will not be published.