Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Tuesday, January 6, 2015 2:48 PM
I have a client that is currently running our software which uses the Environment.SpecialFolder.CommonApplicationData variable in C# as the base location to save all our config/data files.
So, for example, the path is Environment.SpecialFolder.CommonApplicationData\Company Name\Product\ or "C:\ProgramData\Company Name\Product\"
is there a way to change this system variable so that it points to another location? The idea is that I can move the data files for C:\ProgramData to another drive, like "D:\ProgramData"
I hope that makes sense.
Thanks,
Bryan
All replies (5)
Tuesday, January 6, 2015 4:38 PM ✅Answered | 1 vote
Just something to consider. Changing the path with SHSetKnownFolderPath is a global change for a given user (and your app requires admin rights). Could be a breaking change for other apps/services. Perhaps it would be better to have the path passed as a parameter to the method you're using to save config data.
Steve
Tuesday, January 6, 2015 5:29 PM ✅Answered
I have a client that is currently running our software which uses the Environment.SpecialFolder.CommonApplicationData variable in C# as the base location to save all our config/data files.
So, for example, the path is Environment.SpecialFolder.CommonApplicationData\Company Name\Product\ or "C:\ProgramData\Company Name\Product\"
is there a way to change this system variable so that it points to another location? The idea is that I can move the data files for C:\ProgramData to another drive, like "D:\ProgramData"
I hope that makes sense.
Thanks,
Bryan
Perhaps provide the app with an administrative capability for altering the storage location and if the new location is writable and readable by the app after the app creates the location if the location does not already exist then move the files to the new location and provide a setting in the registry for the app to use to locate those files on startup or something.
Although some system locations are used typically for locating files used by an app it doesn't seem like that should be a requirement if an admin has a reason to use a different location.
Maybe the app is installed on the C drive and the D drive doesn't have a windows format with regard to special folders. Yet the admin wants to create a folder there for storing data not using "CommonApplicationData" as a folder name in the path.
La vida loca
Tuesday, January 6, 2015 4:28 PM | 1 vote
The value comes from the system and cannot be changed by the app itself. You can change it via the Win32 API if you are an admin. To do that use P/Invoke and call SHSetKnownFolderPath. Technically this is stored in the registry but you should use the API.
Michael Taylor
http://blogs.msmvps.com/p3net
Tuesday, January 6, 2015 4:57 PM
I agree with Steve. Though you can change this it may result breaking other application. Why don't you store your new path in the application and change reference to Environment.SpecialFolder.CommonApplicationData to the new one?
Wednesday, January 7, 2015 8:36 PM
Thanks steve and I agree. But this is an older application that's already out in the field, it's an extradanory circumstance.