2 개의 companys에 대한 설정을 저장하기 위해 앱 구성을 사용하고 싶습니다. 섹션을 사용하여 서로 다른 키를 제공하는 대신 다른 데이터를 구분할 수 있다면 더 좋을 것입니다.C# 4.0 app.config의 섹션을 어떻게 사용합니까?
나는 온라인으로 확인해 왔지만 사람들이 섹션을 사용하거나 구식의 쉬운 방법으로 그들을 사용할 때 다소 압도적 인 것으로 보인다. 누구든지 나에게 초보자 가이드를 건네 줄 수 있니?
아래는 내의 app.config의 모습 내용의 예입니다
<configSections>
<section name="FBI" type="" />
<section name="FSCS" type="" />
</configSections>
<FSCS>
<add key="processingDirectory" value="C:\testfiles\ProccesFolder"/>
</FSCS>
<FBI>
<add key="processingDirectory" value="C:\testfiles\ProccesFolder"/>
</FBI>
업데이트 : anwer에 따라
고급 솔루션입니다. 누군가가 알고 싶었을 경우에 대비해.
의 App.config :
<configuration>
<configSections>
<sectionGroup name="FileCheckerConfigGroup">
<section name="FBI" type="System.Configuration.NameValueSectionHandler" />
<section name="FSCS" type="System.Configuration.NameValueSectionHandler" />
</sectionGroup>
</configSections>
<FileCheckerConfigGroup>
<FSCS>
<add key="processingDirectory" value="C:\testfiles\ProccesFolder"/>
</FSCS>
<FBI>
<add key="processingDirectory" value="C:\testfiles\ProccesFolder"/>
</FBI>
</FileCheckerConfigGroup>
</configuration>
코드 : 다음
// Get the application configuration file.
System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
// Get the collection of the section groups.
ConfigurationSectionGroupCollection sectionGroups = config.SectionGroups;
foreach (ConfigurationSectionGroup sectionGroup in sectionGroups)
{
if (sectionGroup.Name == "FileCheckerConfigGroup")
{
foreach (ConfigurationSection configurationSection in sectionGroup.Sections)
{
var section = ConfigurationManager.GetSection(configurationSection.SectionInformation.SectionName) as NameValueCollection;
inputDirectory = section["inputDirectory"]; //"C:\\testfiles";
}
}
}
어떻게 사용하는 회사의 데이터 알 수 있습니까? FBI에있는 사용자를 어떻게 알 수 있습니까? – DOK
입력 디렉토리를 설정 한 후에는 해당 회사에서 일할 수있는 방법이 있습니다. – Andy