Skip to content

Instantly share code, notes, and snippets.

@eocron
Created July 2, 2019 09:10
Show Gist options
  • Save eocron/293f3d9dcff4b475670b05f597ba3103 to your computer and use it in GitHub Desktop.
Save eocron/293f3d9dcff4b475670b05f597ba3103 to your computer and use it in GitHub Desktop.
Retrieves full path, regardless where is executing directory. It is essential method for testing and when running services under system32 path.
public static class PathHelper
{
private static readonly string DataPath;
static PathHelper()
{
var assembly = Assembly.GetAssembly(typeof(PathHelper));
var codebase = assembly.CodeBase.Replace("file:///", "");
var baseDir = Path.GetDirectoryName(codebase);
DataPath = baseDir;
}
/// <summary>
/// Retrieves full path, regardless where is executing directory.
/// It is essential method for testing and when running services under system32 path.
/// </summary>
/// <param name="filePath"></param>
/// <returns></returns>
public static string GetFullPath(string filePath)
{
return Path.Combine(DataPath, filePath);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment