jay_t55
jay_t55

Reputation: 11652

Saving session data to ApplicationData Folder (Windows 7/WindowsVista/WindowsXP)

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");

Upvotes: 1

Views: 1624

Answers (1)

Michael Madsen
Michael Madsen

Reputation: 54999

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.

Upvotes: 3

Related Questions