Connect with Expertise | Find Experts, Get Answers, Share Insights

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

C
 
Join Date: Jan 2007
Posts: 374
#1: Feb 15 '10
Hi,

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

The app.config of FormA is as below

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <configuration>
  3.   <appSettings>
  4.     <add key="company" value="DSRC"/>
  5.     </appSettings>
  6. <connectionStrings>
  7. <add name="test" connectionString="Testing Connection String"/>
  8. </connectionStrings>
  9. </configuration>
  10.  
Now I have another application named as Form B.

I want to retrieve both appsettings and connectionstrings 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

✓ answered by cmrhema

The post has been resolved.
I looked here...
http://social.msdn.microsoft.com/For...3-da231a701384

tlhintoq's Avatar
E
C
 
Join Date: Mar 2008
Location: Arizona, USA
Posts: 3,476
#2: Feb 15 '10

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


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.

Expand|Select|Wrap|Line Numbers
  1. 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.
C
 
Join Date: Jan 2007
Posts: 374
#3: Feb 16 '10

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


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
Expand|Select|Wrap|Line Numbers
  1. ExeConfigurationFileMap filename= new ExeConfigurationFileMap();
  2. fileMap.ExeConfigFilename = @"D:\Home\FormA\FormA\bin\Debug\FormA.exe";
  3.  
  4.  
  5. Configuration config =
  6.    ConfigurationManager.OpenMappedExeConfiguration(filename,
  7.    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 connectionstrings.

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 connectionstrings.
The client wants to modify these, hence the need for controlling appsettings for the whole package arises.
Please do not suggest to add ConfigurationSettings into the appsettings, as my request has been turned down by my TL
C
 
Join Date: Jan 2007
Posts: 374
#4: Feb 16 '10

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


The post has been resolved.
I looked here...
http://social.msdn.microsoft.com/For...3-da231a701384
tlhintoq's Avatar
E
C
 
Join Date: Mar 2008
Location: Arizona, USA
Posts: 3,476
#5: Feb 16 '10

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


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

Happy to see you have this resolved.
Reply