12 Ocak 2011, ÇARŞAMBA
Nasıl bölümler c# 4.0 uygulamasını kullanın.config?
Kullanmak istiyorum benim app config ayarları saklamak için 2 şirketin ve tercih ederdim eğer mümkünse kullanmak için bir bölümü için ayrı veriler için birinden diğerine ziyade vererek onlara farklı anahtar adları.
online kontrol edilmiştir ama biraz insanlar bölümleri kullanın veya bunları kullanma tarihi geçmiş kolay yollar bulmak bunalmış almak gibi görünüyor. kimse bana bunları acemi bir rehber verebilir mi?
aşağıda ne benim app bir exampkle.config gibi görünecektir.
<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>
Güncelleme:
Gelişmiş çözüm cevap dayalı. durumda kimsenin bilmesini istedim.
App.config:
<FileCheckerConfigGroup>
<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>
Kod:
// 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";
}
}
}
CEVAP
12 Ocak 2011, ÇARŞAMBA
<configSections>
<section name="FBI" type="System.Configuration.NameValueSectionHandler" />
<section name="FSCS" type="System.Configuration.NameValueSectionHandler" />
</configSections>
<FSCS>
<add key="processingDirectory" value="C:\testfiles\ProccesFolder"/>
</FSCS>
<FBI>
<add key="processingDirectory" value="C:\testfiles\ProccesFolder"/>
</FBI>
Ve sonra:
var section = ConfigurationManager.GetSection("FSCS") as NameValueCollection;
var value = section["processingDirectory"];
Bunu Paylaş:
Nasıl grep sadece dosya adları (in-lin...
NuGet nasıl yüklemek için paketleri tü...
Nasıl SERİ en az veya en fazla özellik...
Nasıl slideDown (veya göstermek) Kulla...
Eclipse diyor ki: “Çalışma alanı kulla...