views:

318

answers:

1

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");
+2  A: 

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.

Michael Madsen
yay! That was easier than I thought it would be. Thank you so much Michael Madsen.
baeltazor