alibasha syed

alibasha syed

  • NA
  • 92
  • 34.1k

Unable to set File Path and Flag Value in app.config.

May 7 2013 12:58 AM
Hi,
     I am having a requirement to prepare a trace log to a  text file which should be configurable based on the value set in app.config file and the path where this text file has to be saved is also need to be set in app.config file.Below is app.config  file
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add key="TextFilePath" value="F:\Ali Data\"/>
  </appSettings>
  <appSettings>
    <add key="TraceLog" value="Yes"/>
  </appSettings>
  <connectionStrings>
    <add name="ContractNoteConnectionString"
        connectionString="Data Source=WAIG-1;Initial Catalog=sto_ea_dev;Persist Security Info=True;User ID=sa;Password=password"
        providerName="System.Data.SqlClient" />
  </connectionStrings>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup>
</configuration>



when I am trying to acces these 2 values from C# like below ..

string

string

I am getting error as Configuration system failed to initialize..I am unable to understand what is the problem.Please help me in this regard.Thanks in advance.


strLogIsRequired = ConfigurationManager.AppSettings["TraceLog"].ToString();
strFilePath = ConfigurationManager.AppSettings["TextFilePath"].ToString();

Answers (1)