Learn about path in C#

Learn about path in C#

If you need to get path of specific folders or files in this article I've created short list of codes for you to save time:

AppData folder path:

Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)

App installation folder (where your app files are located)

System.IO.Path.GetDirectoryName(
System.Reflection.Assembly.GetExecutingAssembly().Location)

// OR

System.IO.Path.GetDirectoryName(
System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)

File path (getting specific file address)

This will get specific file from AppData folder

Path.Combine(Environment.GetFolderPath(
    Environment.SpecialFolder.ApplicationData), "MyFile.dll");

Now if you want to get file path from installation (root) folder of your application, all you have to do is to change Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) part with codes I've shared above. (Don't forget to change file name as well).


To learn more about path class you can refer to official documentation on Microsoft website.

- Last updated 3 weeks ago

Be the first to leave a comment.

You must login to leave a comment