On the local system, is there a (reasonably) guaranteed place to create a directory structure to write files? I'm looking for a solution that does not require Administrative Privileges for permission changes?
After a bit of research, I've seen this answer for finding the current user's desktop folder. I could use this, but what other options are available?
Putting together research:
System.Environment.SpecialFolder
Enumeration
Consider using the isolated storage classes.
Isolated storage gives you a storage location that is associated with a given user and assembly; it works in not-fully-trusted environments and it can use roaming to keep the user's data present even on different machines. See
http://msdn.microsoft.com/en-us/library/System.IO.IsolatedStorage.aspx
for details.
The special folders are, in fact, special because there is a reasonable guarantee that they will be present.
No other folders have such a guarantee. Even C:\
is not guaranteed (though it is quite likely to be present on the vast majority of Windows systems).
A custom folder under ApplicationData is a common place to write application specific data for a given user or CommonApplicationData
for application data to be shared across all users on the system..
In environments where roaming is implemented (the user's data comes with him, no matter which physical server he logs onto), ApplicationData
will follow the user. If you do not wish that behavior, you can use LocalApplicationData
instead.
AppData path is probably what you want. This folder in windows XP+ can be referenced with
string folder = System.Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);
Commonly an application creates a sub folder under this to store its data and it doesn't require any special permissions to read/write into.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With