Home > Net >  Ask a question, about the AppConfig file operations
Ask a question, about the AppConfig file operations

Time:09-25

Application is configured with the Config file, need to manually add section node information, user requirements in program implementation, excuse me, how to implement, not thinking now

CodePudding user response:

 private void button1_Click (object sender, EventArgs e) 
{
The Configuration config=ConfigurationManager. OpenExeConfiguration (ConfigurationUserLevel. None).
TestConfig tc=new TestConfig ();
Tc TestStr="333";
The config. Sections. The Add (" TestConfig ", tc);
The config. Save (ConfigurationSaveMode. Full);
}

Public sealed class TestConfig: ConfigurationSection
{
Public static TestConfig GetConfig ()
{
TestConfig TestConfig section=GetConfig (" ");
The return section.
}
Public static TestConfig GetConfig (string sectionName)
{
TestConfig section=(TestConfig) ConfigurationManager. GetSection (sectionName);
If (section==null)
Throw new ConfigurationErrorsException (sectionName "Section" + + "is not found.");
The return section.
}

[ConfigurationProperty (" TestStr IsRequired=false)]
Public string TestStr
{
The get
{
Return (string) base [" TestStr "];
}
Set
{
The base [" TestStr "]=value;
}
}
}

CodePudding user response:

You this is already done

CodePudding user response:

AppConfig is an XML,
  •  Tags:  
  • C#
  • Related