Question

I am trying to save session data to the users local ApplicationData folder, but it Windows just seems to create a new ApplicationData folder with the files inside it wherever it wants. Sometimes it ends up on my desktop, and sometimes it's elsewhere. (like the bin folder, for example).

It doesn't make any sense.

I know that it redirects due to insufficient permissions etc but this is just horrible.

Can somebody please tell me if this is the right way to save some text file info to my applications AppData folder?

File.WriteAllText(
       Environment.SpecialFolder.ApplicationData +
           "\\MyApplicationNameFolder\\" +
           filename + ".txt");
Was it helpful?

Solution

Environment.SpecialFolder is an enumeration representing the constants you need to use when requesting the path. It doesn't give you the path.

Use GetFolderPath with that enumeration value to get the path.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top