Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Working with Windows Forms Configuration Files in .NET 2.0 and Visual Studio 2005 : Page 2

The newest version of the .NET framework extends strong data typing to configuration files, adds scope for settings, a GUI-based property editor, and drops the read-only restriction for configuration classes.


advertisement
The ThisConfigEditor Application
The downloadable code for the sample application presented here, ThisConfigEditor (see Figure 1), is a simple tool that displays settings from its own configuration file. While simplistic, this application serves as an excellent jumping off point for the needs of most applications. Visual Studio generates most of the files in this project automatically (see Figure 2).

 
Figure 1. The Sample Configuration Editor: This tool displays settings from the sample project's configuration file.
 
Figure 2. Project Files: The figure shows the files generated by Visual Studio for the sample project, with the added "ThisConfigEditor.cs" file.
The only file that needs direct work in a code editor is the ThisConfigEditor.cs file. This application does not require any special assembly manifest or resources and all the configuration settings are handled by Visual Studio's new Properties Editor. When Visual Studio creates a new project it automatically generates a Properties folder and populates it with classes that wrap the configuration settings you generate with the Properties Editor. The Properties Editor updates the app.config file and the Settings.cs class file (the class wrapper around the generated properties) automatically, so you don't need to work with either of these files manually; in fact, you should only do so after you have a thorough understanding of the underpinnings of the new configuration file markup. You can find a full explanation for the configuration file markup tags at Microsoft's MSDN site.
 
Figure 3. The Properties Editor: You reach the configuration (settings) editor by double-clicking on the "Settings.settings" entry in the Solution Explorer.
The Property Editor
Double clicking on the "Settings.settings" entry in the Solution Explorer launches the Properties Editor.

Figure 3 shows two configuration properties created for demonstration purposes; FilesDirectory and Connection. The Properties Editor grid lets you specify the name, the datatype, the scope (by default there are only two scopes: User and Application) and the value. The most interesting property here is the Connection setting. Selecting (Connection string) from the Type dropdown launches a series of dialogs (though interestingly enough not a wizard) for creating the connection string (shown in Figure 4 and Figure 5).

 
Figure 4. Choosing a Data Source: When you select the connection string setting type from the Type dropdown, Visual Studio launches a series of dialogs for defining the connection properties.
 
Figure 5. The Connection Properties Dialog: This standard connection properties dialog appears after you select a connection string type.


Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap