C# : Get Executing Assembly Folder Path

In C#, we can read directory path of executing assembly file using different methods. In this article, I am going write C# code sample to get executing assembly directory path using Assembly and AppDomain classes.

Get Executing Assembly Folder Path using CodeBase

public static string GetAssemblyPathByCodeBase()
{
    string codeBase = Assembly.GetExecutingAssembly().CodeBase;
    UriBuilder uri = new UriBuilder(codeBase);
    return Path.GetDirectoryName(Uri.UnescapeDataString(uri.Path));
}

Read Executing Assembly Directory Path using Assembly Location

public static string GetExecutingDirectoryByAssemblyLocation()
{
    string path= Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
    return path;
}

Get Executing Assembly Folder Path using AppDomain

public static string GetExecutingDirectorybyAppDomain()
{
    string path = AppDomain.CurrentDomain.BaseDirectory;
    return path;
}
Advertisement

Leave a Comment