app.config dosyası
app.config dosyası projeye eklenir. Dosya şuna benzer. key/value çiftleri şeklindedir.
Dosya şuna benzer.
ConfigurationManager sınıfı
Bu sınıfı kullanmak için şu satırı dahil ederiz.
app.config dosyasını okumak için ConfigurationManager sınıfı kullanılır. app.config dosyası host application içinde olmalıdır. DLL projesi içindeyse otomatik olarak okunmaz!
ConfigurationManager sınıfınının kendisi ve içindeki her Property static'tir.
Bu sınıf iki tane static Property sunar. Bunlar AppSettings ve ConnectionStrings nesneleridir. AppSettings app.config ile kullanılır. ConnectionStrings ise webconfig ile kullanılır.
app.config dosyası projeye eklenir. Dosya şuna benzer. key/value çiftleri şeklindedir.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="countoffiles" value="7" />
<add key="logfilelocation" value="abc.txt" />
</appSettings>
</configuration>
webconfig dosyasıDosya şuna benzer.
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
</system.web>
<connectionStrings>
<add name="#" connectionString="#" providerName="..."/>
<connectionStrings>
</configuration>
ConfigurationManager sınıfı
Bu sınıfı kullanmak için şu satırı dahil ederiz.
using System.Configuration;
AppSetting Alanıapp.config dosyasını okumak için ConfigurationManager sınıfı kullanılır. app.config dosyası host application içinde olmalıdır. DLL projesi içindeyse otomatik olarak okunmaz!
ConfigurationManager sınıfınının kendisi ve içindeki her Property static'tir.
Bu sınıf iki tane static Property sunar. Bunlar AppSettings ve ConnectionStrings nesneleridir. AppSettings app.config ile kullanılır. ConnectionStrings ise webconfig ile kullanılır.
string configvalue1 = ConfigurationManager.AppSettings["countoffiles"];
string configvalue2 = ConfigurationManager.AppSettings["logfilelocation"];
Hiç yorum yok:
Yorum Gönder