如何从其他应用程序编辑app.config文件的值? [英] how to edit values of app.config file from another application?

查看:86
本文介绍了如何从其他应用程序编辑app.config文件的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我有两个Windows应用程序项目在同一解决方案中说A和B。我已经在app.config文件中设置了所有键值A。现在我要求我必须让一个exe表示winform包含文本框,我必须为app.config文件设置A的所有键值。这个exe是我的项目B。现在我尝试了很多方法来访问项目A的配置文件。但我失败了。我也试过ConfigurationManager.OpenExeConfiguration(path)但这里需要文件路径,我无法硬编码。我被限制放置任何硬编码路径。



注意:我创建了安装项目,并添加了两个项目输出,以便两个项目exes和A的app.config将在同一个文件夹中,这样它很容易找到文件。



有没有办法实现这个目标。

请建议我,

感谢大家。



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.

<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>





我有上面的配置文件,我想通过winform app更改其键值,如ADMIN-PC。其中包含来自文本框的表格坦克文本。



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.

推荐答案

如果您正在寻找共享配置,那么您使用了错误的存储机制,或者如果您正在寻找read\write配置再次出错机制。如果两个应用程序都需要共享配置而且\或者已经读取了'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\重新缺失的是app.config文件由开发环境(Visual Studio)使用,它不会被完成的应用程序使用,因此对其进行的任何更改都不会影响应用程序在运行时,也不会影响应用程序重新启动。当VS编译你的项目(myproject.exe)时,它会将app.config的内容复制到一个名为myproject.exe.config的文件中,这是程序集实际查看的配置文件。



无论如何,如上所述忘记app.config,它不是为你想要做的而设计的。
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.


这篇关于如何从其他应用程序编辑app.config文件的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆