LocationMy.Settings DescriptionUse the My.Settings object to manage application-specific and user-specific settings for an application. The 2002 and 2003 releases of Visual Basic included a generic configuration system for projects, but it had certain deficiencies, including the inability to manage strongly typed data. The new configuration system included with Visual Basic 2005 resolves many of the deficiencies present in those earlier releases. Settings are initially managed in Visual Studio through the new Settings panel of the project's Properties window. (Access this window by double-clicking on the "My Project" item in the Solution Explorer or by selecting Properties from Visual Studio's Project menu.) This form lets you add configuration settings to a project, including the name, data type, scope (application or user), and initial value of each setting. The name of each setting automatically becomes a property of the My.Settings object. For example, if you add an Integer setting called AlarmDuration to the list of settings, it can be accessed in your code as: My.Settings.AlarmDuration and it will be strongly typed as an Integer. If it is a user-scoped value, the code can update its value through direct assignment. My.Settings.AlarmDuration = 5 The settings are automatically saved when the programs exits, depending on the setting of the My.Application.SaveMySettingsOnExit property. When developing an application in Visual Studio, the settings defined through the Project Properties window are stored in the app.config file for the project. Once your application is deployed, the application-scoped settings and the user-scoped settings for each user are stored in different files. Each user's settings are usually stored in: C:\DocumentsandSettings\LocalSettings\ApplicationData\companyName\hashedAppDomain\version\user.config where companyName is the assembly-defined company name for your project, hashedAppDomain is constructed from the application-related values, and version is the four-part, dot-delimited assembly version number. It's somewhat complex, but it is also uniquely identifiable. The application-scoped settings (and the default versions of all user-scoped setting) are stored in the Settings.settings file, found in the same folder as the assembly file. Public MembersEach setting added to your project through the Project Properties window becomes a property in the My.Settings object. In addition to these, there are several members used to manage the settings.
Usage at a Glance
Related Framework Entries
See AlsoForms Object, My Namespace, Resources Object, SaveMySettingsOnExit Property, WebServices Object |