There are a number of details to note about the configuration file settings.
A in general, the configuration document defaults to the value in the AppSettings property under it.
The following is the common VB Code implementation method:
Dim Exefilemap as Execonfigurationfilemap = New Execonfigurationfilemap ()
Exefilemap.execonfigfilename = ConfigFilePath
Dim Configcache as Configuration
= Configurationmanager.openmappedexeconfiguration (Exefilemap, Configurationuserlevel.none)
Dim Rtnvalue = configCache.AppSettings.Settings (strkey). Value
B for customer-defined sections must be placed in configsections when reading these section procedures.
It needs to be judged according to the App. Config file path.
(1) for the default path, the app. Config can be used directly
Dim nb as System.Collections.Hashtable
= CType (System.Configuration.ConfigurationManager.GetSection ("Majorcommands"), _
System.Collections.Hashtable)
Dim rtnvalue = NB (strkey)
(2) for a man-defined path, that is, the case in a
Dim myparamssection as ConfigurationSection = Configcache.getsection ("Usersection")
Dim myparamssectionrawxml As String = MyParamsSection.SectionInformation.GetRawXml () Dim sectionxmldoc As Xml.xmldo Cument = new Xml.xmldocument () sectionxmldoc.load (new StringReader (myparamssectionrawxml)) Dim handler as Na Mevaluesectionhandler = New NameValueSectionHandler () Dim handlercreatedcollection as Specialized.namevaluecollecti On handlercreatedcollection = CType (handler. Create (Nothing, Nothing, sectionxmldoc.documentelement), specialized.namevaluecollection) If not Handlercreatedcoll Ection. Allkeys.contains (key) then return Defaultdata Else return handlercreatedcollection (key) End If
The configuration file needs to be increased
<configSections> <section name = "Usersection" type = "System.Configuration.DictionarySectionHandler "/> </configSections>
<appSettings></appSettings>
<USERSECTION>
<!--customize--> <add key = "Key1" value = "Shinsho"/> <add key = "Key2" value = "SOJITZ"/> <add Key = "Key3" value = "SUMITOMO"/> <add key = "Key4" value = "MITSUBISHI ELECTRIC"/> <add key = "Key5" value = "MITSUBISHI"/> </USERSECTION>
Of course, the same effect can be achieved if the control is read directly from the XML.
If you have any doubts, please read the Microsoft source code directly
https://referencesource.microsoft.com/#System. Configuration
. Discussion on configuration and configurationmanager/appsettings and configsections in net environment