Click here to Skip to main content
15,917,005 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello everyone,

I have two windows application project says "A" and "B" in same solution. I already sets all key values in app.config file of "A" . Now I got requirement that I have to make one exe says winform contaings textboxes where I have to set all key values for app.config file of "A" . this exe is my project "B". now i tried many ways to get access of config file of project A . but i failed. I also tried with "ConfigurationManager.OpenExeConfiguration(path)" but here needs file path which i could not put hardcoded. I am restricted to put any hardcoded paths.

note: I created setup project and added both projects output so that both projects exes and app.config of "A" will be in same folder so that its easy to locate file.

Is there any way to achieve this.
Please suggest me ,
Thanks to everyone.

C#
<appSettings>
    <add key="DataSource" value="ADMIN-PC"/>
    <add key="DBname" value="DATA_ABHISHEK"/>
    <add key="Security" value="True"/>
    <add key="UserName" value=""/>
    <add key="Passward" value=""/>
    <add key="hourrate" value="60"/>
    <add key="port" value="2030"/>
  </appSettings>
</configuration>


I have above config file and i want to change its key values like "ADMIN-PC" by winform app. which contains form tanking text from textbox.
Posted
Updated 20-Oct-15 22:15pm
v3
Comments
Sergey Alexandrovich Kryukov 21-Oct-15 3:46am    
It makes no sense at all. This is not the config mechanism is designed for. Use some other mechanism. If you explain the ultimate goal of all this activity, perhaps I could help you. To start with, you have to isolate your understanding of "project" from any runtime entities, such as application and assembly. During runtime, there are no projects.
—SA

1 solution

If you're looking for shared configuration then you're using the wrong storage mechanism, or if you're looking for read\write configuration again wrong mechanism. If both apps need to share config and\or have read\write config then you should use the registry.

The thing about the app.config file you're missing is that the app.config file is used by your development environment (Visual Studio) it is *not* used by the finished app so any changes made to it will not affect the app while it is running, nor when the app is restarted. When VS compiles your project (myproject.exe) it copies the content of app.config into a file called myproject.exe.config and that is the config file the assembly actually looks at.

Anyway, as above forget app.config, it is not designed for what you want to do.
 
Share this answer
 
v2
Comments
Member 11543226 21-Oct-15 4:35am    
so tell me the way which mechanism you are talking about i need to get this mechanism.
Sinisa Hajnal 21-Oct-15 4:59am    
He told you to use registry. I'm suggesting SETTINGS table in your database. Both implementations are easily done. If you don't know registry, do some research, it is very easy with .NET, but your app may have trouble on the machines where user / app is hasn't admin rights. That's why I'm suggesting table in your database.
F-ES Sitecore 21-Oct-15 5:46am    
Use the registry, that's what it's there for :)
Member 11543226 21-Oct-15 5:20am    
I cannot add table to database because its others database i dont have write to access modify or add table to it

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900