Skip to content

Instantly share code, notes, and snippets.

@mishrsud
Last active March 10, 2016 02:49
Show Gist options
  • Save mishrsud/44b1e4db680f5ac600f1 to your computer and use it in GitHub Desktop.
Save mishrsud/44b1e4db680f5ac600f1 to your computer and use it in GitHub Desktop.
Get Directory of Executing assembly
/// 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