App. Config configures a multi-item configuration collection Custom Configuration

Source: Internet
Author: User

C # program configuration file, the most used is appsettings under the <add key= "Interval" value= "/>", this configuration item is very convenient, but the configuration of the collection is not convenient (of course, you can use a comma separated, key=key1, Key2,key3 ... But you still don't know how many collections there are. Now give the solution.

Requirements: The program Super Administrator in this way, configured in App. config, you can configure multiple. After successful login, read config to see if I am super admin.
(Of course, the demand is very lame, because I'm trying to give an example, I made it up, whoa, ha)


1. Download configurationsectiondesigner_2.0.1.7.vsix, install;
2. Re-open vs, new test engineering WindowsFormsApplication2;
3. Right-click on the project, add New item, select in Configuratesectiondesiger, name is ConfigurateSectionDesiger1;
4. Double-click ConfigurateSectionDesiger1, open his design page, click "Toolbox";
5. Drag a configuration section to the page, named Usersection;
6. Click usersection elements, add element, named Users
7. Toolbox Drag a configurationelementcollection to the page, named Usercollection ;
8. Click on the user's properties in Usersection, select the type: Usercollection, at this time usersection and usercollection appear arrow connection;
9. Toolbox, drag a configuration Element named user. Add attributes,id,name,gender,pwd to user and specify the type of each attributes as String, Set the is key of the ID to true.
10. Set the item type for usercollection to user.
11. Look under CONFIGURATIONSECTIONDESIGNER1.CSD, there is a file ConfigurationSectionDesigner1.csd.config
12. Open ConfigurationSectionDesigner1.csd.config, and copy the contents of the configsections and usersection tags into the configuration node of App. Config.

<configsections><section name= "usersection" type= "windowsformsapplication2.usersection, WindowsFormsApplication2, version=1.0.0.0, Culture=neutral, Publickeytoken=null "/></configsections>< Usersection xmlns= "Urn:windowsformsapplication2" ><!--This was just a minimal sample configuration file that shows Ho W to declarethe configuration sections. Because an XML Schema Definition (XSD) are generated for each configurationsection, it should are trivial to edit these file s because haveintellisense on the XML definition.--></usersection>

  

13. Now configured, in the App. Config, under the usersection node, tapping "<", will appear the users of the smart prompt, the users under the "<", will appear the user's prompt, while the user and Id,name, Gender,pwd these properties
14. Read method

var section = (usersection) System.Configuration.ConfigurationManager.GetSection ("Usersection"), for (int i = 0; i < Section. Users.count; i++) {String ID = section. users[i].id;string name = section. Users[i]. name;string Pwd = section. Users[i]. PWD; String Gender = section. Users[i]. Gender;}

  

Note: The configsections node in app. Config must be placed at the beginning. That is, at the beginning of the configuration node

App. Config configures a multi-item configuration collection Custom Configuration

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.