How to Get the Path of the Current User's "Application Data" Folder

How can i get the path of the current user's Application Data folder?

Look at combining Environment.GetFolderPath and Environment.SpecialFolder to do this.

Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)

how to get users' application data folder using C#?

Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)

How to get Application Data folder path programmatically in C#?

This will get the directory of the ApplicationData folder (or any other special system folder):

var appDataPath
= Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);

VBA How to get path to The Current Users Application data folder?

You can use Environ("AppData") to get this path. Environ will pull any system variable, which can be found by using the set command at the DOS prompt.

How can I get the path to the %APPDATA% directory in Python?

import os
print os.getenv('APPDATA')

C++ : How to get actual folder path when the path has special folder names

The Win32 API that expands environment variable references of the form %variable% in strings is ExpandEnvironnmentStrings.

C# getting the path of %AppData%

To get the AppData directory, it's best to use the GetFolderPath method:

Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)

(must add using System if not present).

%AppData% is an environment variable, and they are not automatically expanded anywhere in .NET, although you can explicitly use the Environment.ExpandEnvironmentVariable method to do so. I would still strongly suggest that you use GetFolderPath however, because as Johannes Rössel points out in the comment, %AppData% may not be set in certain circumstances.

Finally, to create the path as shown in your example:

var fileName = Path.Combine(Environment.GetFolderPath(
Environment.SpecialFolder.ApplicationData), "DateLinks.xml");


Related Topics



Leave a reply



Submit