<p>I have a .NET 2.0 Windows Forms application. Where is the best place the store user settings (considering Windows guidelines)?</p>

<p>Some people pointed to <code>Application.LocalUserAppDataPath</code>. However, that creates a folder structure like:</p>

<blockquote>
  <p>C:\Documents and Settings\user_name\Local Settings\Application
  Data\company_name\product_name\product_version\</p>
</blockquote>

<p>If I release version 1 of my application and store an XML file there, then release version 2, that would change to a different folder, right? I'd prefer to have a single folder, per user, to store settings, regardless of the application version.
­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­</p>

[{'answer_id': 26377, 'author': 'LeoD', 'author_id': 2868, 'author_profile': 'https://Stackoverflow.com/users/2868', 'pm_score': 0, 'selected': False, 'text': "<p>Settings are standard key-value pairs (string-string). I could wrap them in an XML file, if that helps.</p>\n\n<p>I'd rather use the file system instead of the registry. It seems to be easier to maintain. In support scenarios, if the user needs to manually open/change the settings, that would be easier if it's in the file system. </p>\n"}, {'answer_id': 26379, 'author': 'Dillie-O', 'author_id': 71, 'author_profile': 'https://Stackoverflow.com/users/71', 'pm_score': 0, 'selected': False, 'text': "<p>I'd go down the folder list you posted except for the product version. You don't want the settings reset after an update is released.</p>\n\n<p>I'm actually moving away from the registry for user settings because of the debug/footprint factor. I'm currently only storing a few basic settings (window size, position, version of a data file) in the registry, and I've run into more problems if an update goes bad or a user loses a second monitor and that is where the application was opening to. A few of them are savvy enough to understand regedit, but for the rest they have to do a reinstall, which is quick, but I think they grumble a bit. With the file based version, all I'd have to do is have them open up an XML file in Notepad and make a quick tweak.</p>\n\n<p>In addition, I'm looking to make my application runnable off a USB flash drive, and having the settings tied into the file seems much friendlier to that process. I'm sure I can do some code to check/clean the registry, but I think most of us are already tired of the registry clutter that seems to eat up our machines nowadays.</p>\n\n<p>I know there are some security tradeoffs to this, but none of the data I'm sorting is that critical to that cause, and I'm not suffering any performance hits due to the size of the application.</p>\n"}, {'answer_id': 26394, 'author': 'Ryan Farley', 'author_id': 1627, 'author_profile': 'https://Stackoverflow.com/users/1627', 'pm_score': 7, 'selected': True, 'text': '<p>I love using the built-in <a href="http://msdn.microsoft.com/en-us/library/a65txexh.aspx" rel="noreferrer">Application Settings</a>. Then you have built in support for using the settings designer if you want at design-time, or at runtime to use:  </p>\n\n<pre><code>// read setting\nstring setting1 = (string)Settings.Default["MySetting1"];\n// save setting\nSettings.Default["MySetting2"] = "My Setting Value";\n\n// you can force a save with\nProperties.Settings.Default.Save();\n</code></pre>\n\n<p>It does store the settings in a similar folder structure as you describe (with the version in the path). However, with a simple call to:  </p>\n\n<pre><code>Properties.Settings.Default.Upgrade(); \n</code></pre>\n\n<p>The app will pull all previous versions settings in to save in. </p>\n'}, {'answer_id': 26414, 'author': 'Jason Z', 'author_id': 2470, 'author_profile': 'https://Stackoverflow.com/users/2470', 'pm_score': 2, 'selected': False, 'text': "<p>One approach that has worked for me in the past has been to create a settings class and use XML serialization to write it to the file system.  You could extend this concept by creating a collection of settings objects and serializing it.  You would have all of your settings for all users in one place without having to worry about managing the file system.</p>\n\n<p>Before anyone gives me any flak for partially re-inventing the wheel, let me say a few things.  For one, it is only a few lines of code to serialize and write the file.  Secondly, if you have an object that contains your settings, you don't have to make multiple calls to the appSettings object when you load your app.  And lastly, it is very easy to add items that represent your applications state, thereby allowing you to resume a long-running task when the application loads next.</p>\n"}, {'answer_id': 26424, 'author': 'Lars Truijens', 'author_id': 1242, 'author_profile': 'https://Stackoverflow.com/users/1242', 'pm_score': 3, 'selected': False, 'text': '<p>Or write your settings in a xml file and save it using <a href="http://msdn.microsoft.com/en-us/library/3ak841sy.aspx" rel="noreferrer">Isolated Storage</a>. Depending on the store you use it saves it in the Application Data folder. You can also choose a roaming enabled store which means when the user logs on a different computer the settings move with them.</p>\n'}, {'answer_id': 26982, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>Isolated storage is primarily used for applications distributed using <a href="http://en.wikipedia.org/wiki/ClickOnce" rel="nofollow noreferrer">ClickOnce</a> and are run in a secure sandbox. The base path is decided for you and you won\'t be able infer it in your code. The path will be something like "\\LocalSettings\\ApplicationData\\IsolatedStorage\\ejwnwe.302\\kfiwemqi.owx\\url.asdaiojwejoieajae....", not all that friendly. Your storage space is also limited.</p>\n\n<p><a href="https://stackoverflow.com/questions/26369/what-is-the-best-way-to-store-user-settings-for-a-net-application/26400#26400">Ryan Farley has it right</a>.</p>\n'}, {'answer_id': 5379459, 'author': 'Jonathan Wood', 'author_id': 522663, 'author_profile': 'https://Stackoverflow.com/users/522663', 'pm_score': 3, 'selected': False, 'text': '<p>.NET applications have a built-in settings mechanism that is easy to use. The problem with it, in my opinion, is that it stores those settings off into a rather obscure directory and end users will not be able to find it. Moreover, just switching from debug to release build changes the location of this directory, meaning that any settings saved in one configuration are lost in the other.</p>\n\n<p>For these and other reasons, I came up with <a href="http://www.blackbeltcoder.com/Articles/winforms/a-custom-settings-class-for-winforms" rel="noreferrer">my own settings code for Windows Forms</a>. It\'s not quite as slick as the one that comes with .NET, but it\'s more flexible, and I use it all the time.</p>\n'}, {'answer_id': 31044553, 'author': 'vitalinvent', 'author_id': 2409677, 'author_profile': 'https://Stackoverflow.com/users/2409677', 'pm_score': 1, 'selected': False, 'text': '<p>I try some methods to store my settings to simply text file and i found best way:</p>\n\n<p>file stored in application folder, to usage , <strong>settings.txt</strong>:\n(inside settings file approved comments, try //comment)</p>\n\n<p>//to get settings value</p>\n\n<pre><code>Settings.Get("name", "Ivan");\n</code></pre>\n\n<p>//to set settings value</p>\n\n<pre><code>Settings.Set("name", "John");\n</code></pre>\n\n<p>using:</p>\n\n<pre><code>using System;\nusing System.Collections.Generic;\nusing System.Runtime.InteropServices;\nusing System.Text;\nusing System.Windows.Forms;\n</code></pre>\n\n<p>//you can store  also with section name, to use just add name section Set(section_name,name,value) and Get(section_name,name,value)</p>\n\n<pre><code>public static class Settings\n{\n    private static string SECTION =  typeof(Settings).Namespace;//"SETTINGS";\n    private static string settingsPath = Application.StartupPath.ToString() + "\\\\settings.txt";\n    [DllImport("kernel32")]\n    private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);\n    [DllImport("kernel32")]\n    private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);\n    public static String GetString(String name)\n    {\n        StringBuilder temp = new StringBuilder(255);\n        int i = GetPrivateProfileString(SECTION,name,"",temp,255,settingsPath);\n        return temp.ToString();\n    }\n    public static String Get(String name, String defVal)\n    {\n        return Get(SECTION,name,defVal);\n    }\n    public static String Get(string _SECTION, String name, String defVal)\n    {\n        StringBuilder temp = new StringBuilder(255);\n        int i = GetPrivateProfileString(_SECTION, name, "", temp, 255, settingsPath);\n        return temp.ToString();\n    }\n    public static Boolean Get(String name, Boolean defVal)\n    {\n        return Get(SECTION, name, defVal);\n    }\n    public static Boolean Get(string _SECTION, String name, Boolean defVal)\n    {\n        StringBuilder temp = new StringBuilder(255);\n        int i = GetPrivateProfileString(_SECTION,name,"",temp,255,settingsPath);\n        bool retval=false;\n        if (bool.TryParse(temp.ToString(),out retval))\n        {\n            return retval;\n        } else\n        {\n            return retval;\n        }\n    }\n    public static int Get(String name, int defVal)\n    {\n        return Get(SECTION, name, defVal);\n    }\n    public static int Get(string _SECTION, String name, int defVal)\n    {\n        StringBuilder temp = new StringBuilder(255);\n        int i = GetPrivateProfileString(SECTION,name,"",temp,255,settingsPath);\n        int retval=0;\n        if (int.TryParse(temp.ToString(),out retval))\n        {\n            return retval;\n        } else\n        {\n            return retval;\n        }\n    }\n    public static void Set(String name, String val)\n    {\n        Set(SECTION, name,val);\n    }\n    public static void Set(string _SECTION, String name, String val)\n    {\n        WritePrivateProfileString(_SECTION, name, val, settingsPath);\n    }\n    public static void Set(String name, Boolean val)\n    {\n        Set(SECTION, name, val);\n    }\n    public static void Set(string _SECTION, String name, Boolean val)\n    {\n        WritePrivateProfileString(_SECTION, name, val.ToString(), settingsPath);\n    }\n    public static void Set(String name, int val)\n    {\n        Set(SECTION, name, val);\n    }\n    public static void Set(string _SECTION,String name, int val)\n    {\n        WritePrivateProfileString(SECTION, name, val.ToString(), settingsPath);\n    }\n}\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/26369', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2868/']