help to create app.config

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Vicky via DotNetMonster.com

    help to create app.config

    Hi,
    Could anyone help me with some info how to create app.config file.
    I need to put code of directory info in there, Thank you very much!

    DirectoryInfo di = new DirectoryInfo(" C:\\Vicky Development\\Fu ndExplorer\\
    Index\\Copy of IntlIndex");
    ---------------------------------------------------------------------

    I know in app.config may like below
    ---------------------------------------------------------------------
    <?xml version="1.0" encoding="utf-8"?>

    <configuratio n>

    <appSettings>

    <!-- User application and configured property settings go here.-->

    <!-- Example: <add key="settingNam e" value="settingV alue"/> -->

    <add key="reportingS ervice.ServerNa me" value="Http://Localhost" />
    <!-- No ending "/" -->

    <add key="connOperat ions.Connection String" value="Integrat ed
    Security=SSPI;P ersist Security Info=False;Data Source=HIRST-IT1\
    TEST;Initial Catalog=FundMan ager42205;" />

    </appSettings>

    </configuration>
    ------------------------------------------------------------------------
    And in the code when I create Reader I do below

    System.Configur ation.AppSettin gsReader appReader =

    new System.Configur ation.AppSettin gsReader()
    ;

    string connString = (string)appRead er.GetValue(

    "connOperations .ConnectionStri ng",typeof
    (string));

    SqlConnection conn = new SqlConnection(c onnString);
    ------------------------------------------------------------------------

    Here is begining part of the code
    ------------------------------------------------------------------
    namespace dataReader

    {

    class Class1

    {


    [STAThread]

    public static void Main(string[] args)

    {

    DirectoryInfo di = new DirectoryInfo(" C:\\Vicky Development\\Fu ndExplorer\\
    Index\\Copy of IntlIndex");



    // Get a reference to each file in that directory.

    FileInfo[] fiArr = di.GetFiles();

    int FundID=0;

    int PeriodicityID = 0;;

    string Ticker=null;

    string currentLine = null;

    //set up sql connection string

    string myConnString= "workstatio n id=HIRST-IT1;packet size=4096;"+

    "Integrated Security=SSPI;i nitial catalog=FundMan ager42205;"+ "Data
    Source=HIRST-IT1\\TEST;"+

    "persist security info=True";



    // for each file in Directory, if TickerName match DB, load data

    foreach (FileInfo fri in fiArr)

    {

    StreamReader sr = new StreamReader("C :\\Vicky Development\\Fu ndExplorer\\
    Index\\Copy of IntlIndex\\"+fr i.Name);

    //read the text file

    //read the first row --header

    currentLine = sr.ReadLine();

    //read the second row contains data

    currentLine = sr.ReadLine();

    -
    -
    -
    -
    -
    }

    --
    Message posted via http://www.dotnetmonster.com
  • Ignacio Machin \( .NET/ C# MVP \)

    #2
    Re: help to create app.config

    Hi,

    First of all you cannot write the app.config file, it's open with a write
    lock for the application, that's why you cannot modify it in your code.

    what you can do is create another file to store the config you need to
    change in your code (you could also use the registry ) to do this you can
    use a simpler var_name=value approach or another xml file with a similar
    struct than the app.config file then read it and parse in your program.


    I prefer to use the first approach though.

    Cheers,
    --
    Ignacio Machin,
    ignacio.machin AT dot.state.fl.us
    Florida Department Of Transportation



    "Vicky via DotNetMonster.c om" <forum@nospam.D otNetMonster.co m> wrote in
    message news:1b964de4b7 b94b32b2f258b76 c5ca9b4@DotNetM onster.com...[color=blue]
    > Hi,
    > Could anyone help me with some info how to create app.config file.
    > I need to put code of directory info in there, Thank you very much!
    >
    > DirectoryInfo di = new DirectoryInfo(" C:\\Vicky
    > Development\\Fu ndExplorer\\
    > Index\\Copy of IntlIndex");
    > ---------------------------------------------------------------------
    >
    > I know in app.config may like below
    > ---------------------------------------------------------------------
    > <?xml version="1.0" encoding="utf-8"?>
    >
    > <configuratio n>
    >
    > <appSettings>
    >
    > <!-- User application and configured property settings go
    > here.-->
    >
    > <!-- Example: <add key="settingNam e" value="settingV alue"/> -->
    >
    > <add key="reportingS ervice.ServerNa me" value="Http://Localhost" />
    > <!-- No ending "/" -->
    >
    > <add key="connOperat ions.Connection String" value="Integrat ed
    > Security=SSPI;P ersist Security Info=False;Data Source=HIRST-IT1\
    > TEST;Initial Catalog=FundMan ager42205;" />
    >
    > </appSettings>
    >
    > </configuration>
    > ------------------------------------------------------------------------
    > And in the code when I create Reader I do below
    >
    > System.Configur ation.AppSettin gsReader appReader =
    >
    > new
    > System.Configur ation.AppSettin gsReader()
    > ;
    >
    > string connString = (string)appRead er.GetValue(
    >
    > "connOperations .ConnectionStri ng",typeof
    > (string));
    >
    > SqlConnection conn = new SqlConnection(c onnString);
    > ------------------------------------------------------------------------
    >
    > Here is begining part of the code
    > ------------------------------------------------------------------
    > namespace dataReader
    >
    > {
    >
    > class Class1
    >
    > {
    >
    >
    > [STAThread]
    >
    > public static void Main(string[] args)
    >
    > {
    >
    > DirectoryInfo di = new DirectoryInfo(" C:\\Vicky
    > Development\\Fu ndExplorer\\
    > Index\\Copy of IntlIndex");
    >
    >
    >
    > // Get a reference to each file in that directory.
    >
    > FileInfo[] fiArr = di.GetFiles();
    >
    > int FundID=0;
    >
    > int PeriodicityID = 0;;
    >
    > string Ticker=null;
    >
    > string currentLine = null;
    >
    > //set up sql connection string
    >
    > string myConnString= "workstatio n id=HIRST-IT1;packet size=4096;"+
    >
    > "Integrated Security=SSPI;i nitial catalog=FundMan ager42205;"+ "Data
    > Source=HIRST-IT1\\TEST;"+
    >
    > "persist security info=True";
    >
    >
    >
    > // for each file in Directory, if TickerName match DB, load data
    >
    > foreach (FileInfo fri in fiArr)
    >
    > {
    >
    > StreamReader sr = new StreamReader("C :\\Vicky Development\\Fu ndExplorer\\
    > Index\\Copy of IntlIndex\\"+fr i.Name);
    >
    > //read the text file
    >
    > //read the first row --header
    >
    > currentLine = sr.ReadLine();
    >
    > //read the second row contains data
    >
    > currentLine = sr.ReadLine();
    >
    > -
    > -
    > -
    > -
    > -
    > }
    >
    > --
    > Message posted via http://www.dotnetmonster.com[/color]


    Comment

    • Vicky via DotNetMonster.com

      #3
      Re: help to create app.config

      Ignacio,

      Thank you so much fo your reply.
      I try to understand you said "you cannot write the app.config file
      it's open with a write lock for the application"

      I did modify a app.config file before to a different server and DB,when I
      did testing, I have to uncheck the Read only to make the changes.


      But I will create a new file as you suggested.
      I noticed that it is common to put server, and DB info in app.config file
      I did not see an example to put Directory or file Path in app.config,
      Do you have any example? I could give a try similiar like server, and DB
      info. Thanks!

      DirectoryInfo di = new DirectoryInfo(" C:\\Vicky Development\\Fu ndExplorer\\
      Index\\Copy of IntlIndex");

      --
      Message posted via http://www.dotnetmonster.com

      Comment

      Working...