This example demonstrates how can we get application or assembly folder.
Geting Directory of the windows forms application
To get directory we need to use static property ExecutablePath from Application in System.Windows.Forms namespace.
By using static method GetDirectoryName of Path class we can get only the folder part of the path.
string appPath = Path.GetDirectoryName(Application.ExecutablePath); |
Getting Directory of loaded assembly
By using the method Assembly.GetExecutingAssembly we can get assembly of currently executing program.
By using method Assembly.GetAssembly we can get assembly in which the specified class is defined. Finally, we can get a assembly file path using Assembly.CodeBase property.
string appPath = Path.GetDirectoryName( Assembly.GetAssembly(typeof(MyClassName)).CodeBase); |

Leave a Reply
You must be logged in to post a comment.