How to obtain app.config of a different application and modify it

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cmrhema
    Contributor
    • Jan 2007
    • 375

    How to obtain app.config of a different application and modify it

    Hi,

    I have two windows application. eg ., FormA and FormB

    The app.config of FormA is as below

    Code:
    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <appSettings>
        <add key="company" value="DSRC"/>
        </appSettings>
    <connectionStrings>
    <add name="test" connectionString="Testing Connection String"/>
    </connectionStrings>
    </configuration>
    Now I have another application named as Form B.

    I want to retrieve both appsettings and connectionstrin gs of Form A into Form B.

    Further I should be able to modify both of these appsettings and connection strings and save it into the Form A.

    I know how to retrieve the appsettings , and connection strings of the same application and modify.

    But how do I obtain of some other application and modify the same.

    Kindly do let me know.


    Regards

    cmrhema
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    You are referring to different forms, but calling them different applications so I'm not sure if you really mean two different applications or two forms in one application.

    If you mean two forms in one application...
    Why does your form A need to know anything about the details of your form B?

    That doesn't really follow the basic tennant of OOP where each object is responsible for itself and nobody else. At most FormA should instruct FormB to load it's settings.

    Code:
    FormB.LoadSettings();
    But FormA shouldn't do it on behalf of FormB.

    If FormA has to know a specific value from FromB, then put a public property in FormB that FormA can reach.

    If you mean some shared data in two different applications...
    Personally I would just put the shared data in the registry so both applications can reach it.

    Comment

    • cmrhema
      Contributor
      • Jan 2007
      • 375

      #3
      Actually I have 4 windows services running under one setup., one webservice and one wcf service and one application.
      All these have different app.configs, comprising of different appsettings and different connection strings.
      I am supposed to create a windows application that will retrieve each of these settings and then save it accordingly.

      I tried upto this level
      Code:
      ExeConfigurationFileMap filename= new ExeConfigurationFileMap();
      fileMap.ExeConfigFilename = @"D:\Home\FormA\FormA\bin\Debug\FormA.exe";
                          
      
      Configuration config =
         ConfigurationManager.OpenMappedExeConfiguration(filename,
         ConfigurationUserLevel.None);
      But then just got struck, I just do not know how to proceed futher (Sounds dumb right !).

      I am able to retrieve all the keys related to appsettings but not the connectionstrin gs.

      And to the reply to your question as why should we be retrieving appsettings is,
      We are going to send this to our client, who will decide the database, In other words database will be changed, further we have set a time for the sockets to recieve data, the polling time, the interval everything under the appsettings and connectionstrin gs.
      The client wants to modify these, hence the need for controlling appsettings for the whole package arises.
      Please do not suggest to add ConfigurationSe ttings into the appsettings, as my request has been turned down by my TL

      Comment

      • cmrhema
        Contributor
        • Jan 2007
        • 375

        #4
        The post has been resolved.
        I looked here...
        The home for technical questions and answers at Microsoft. Get started asking, answering, and browsing questions about products like .Net, Azure, or Teams.

        Comment

        • tlhintoq
          Recognized Expert Specialist
          • Mar 2008
          • 3532

          #5
          Google and MSDN to the rescue! Hurray! Hazaa hazaa. The crowd goes wild.

          Happy to see you have this resolved.

          Comment

          Working...