Last active
March 10, 2016 02:49
-
-
Save mishrsud/44b1e4db680f5ac600f1 to your computer and use it in GitHub Desktop.
Get Directory of Executing assembly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Use most of the time | |
public static string GetExecutingDirectoryName() | |
{ | |
var location = new Uri(Assembly.GetEntryAssembly().GetName().CodeBase); | |
return new FileInfo(location.AbsolutePath).Directory.FullName; | |
} | |
/// In case of tests or when we know what we're doing | |
/// This works in ASP.NET Web API | |
public static string GetExecutingDirectoryNameForTests() | |
{ | |
var location = new Uri(Assembly.GetExecutingAssembly().GetName().CodeBase); | |
var dirName = new FileInfo(location.AbsolutePath).Directory.FullName; | |
return Uri.UnescapeDataString(dirName); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Reference: https://www.simple-talk.com/blogs/2015/01/14/c-getting-the-directory-of-a-running-executable/