Search code examples
c#appdata

How can I create a folder in the app folder in the user's AppData folder e.g. C:\User\AppData?


I've tried this:

var systemPath = System.Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);
var complete = Path.Combine(systemPath, extractfilename);

But it results in:

C:\ProgramData\Extract.txt

My expected output is:

C:\User\AppData\Extract.txt


Solution

  • You need to create file in Environment.SpecialFolder.ApplicationData folder. There is another way also to get its value, so you can use it also and append the path.

    e.g.

    string path;
    path = @"%AppData%\test";
    
    Environment.ExpandEnvironmentVariables(path);