Store information in a file that persists after uninstall
I'm developing an application that will be published via ClickOnce. I've been using the Application.ExecutablePath
folder to store some licensing information. Now, I want the application to check for updates, but whenever it does the license file get lost and the user needs to enter the information again. Seems like C开发者_高级运维lickOnce is basically uninstalling and reinstalling the new version of the application. I could save the license file somewhere in the System folder, but that's an ugly solution. Another file with the same name could already exist in there, or I might get access denied exceptions or stuff like that. I'm not trying to hide the file. And I need the folder to be accessible without administrator privileges.
So what's the best and safest way I can store a file that will stay after I uninstall (or update) the application?
I think you should store it in the common application data place. You can get the folder path by the following code
Environment.GetFolderPath(System.Environment.SpecialFolder.CommonApplicationData);
This folder is a built-in special folder. It's main purpose is to store shared application data for all the users using the same application. Usually, you would like to create a sub folder with your compaany name and product name under that folder so that it won't conflict with other application. If your don't want to share your license key to all users on the same machine, you can use System.Environment.SpecialFolder.ApplicationData
instead.
I have seen many applications hide their license settings in the Registry - sometimes hiding under clever key names. I hate it as a user, but if you like to keep the data I think registry is the best.
精彩评论