Created
July 2, 2019 09:10
-
-
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.
This file contains hidden or 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
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