从任何应用程序编辑任何配置文件 [英] Edit any configuration file from any application

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

问题描述

那边是Hy。我想创建一个可以修改任何配置文件的应用程序。我打开一个文件对话框,选择文件,用文件中的信息填充一些框,最后有一个保存信息按钮。我可以这样做吗?



  private   void  metroButton1_Click( object  sender,EventArgs e)
{
OpenFileDialog openFileDialog1 = OpenFileDialog();
openFileDialog1.Filter = 配置文件| * .config;
openFileDialog1.Title = Slecteazăunfişierdeconfigurări;
if (openFileDialog1.ShowDialog()== DialogResult.OK)
{
textBox1.Text = openFileDialog1.FileName;
filename = openFileDialog1.FileName;
}
}





  string  appName =   AdministrareRetele.exe; 
配置config = ConfigurationManager.OpenExeConfiguration(appName);
ConnectionStringsSection section = config.GetSection( connectionStrings as ConnectionStringsSection;







我不知道该放什么ConfigurationManager......



谢谢!



编辑



我可以从CURRENT应用程序的配置文件中获取所需的所有信息。但我希望能够获取和修改其他应用程序的信息。



当前情况:



我有2个文件:SAME文件夹中的App.exe和app.config。我写这段代码:



  string  appName =   App.exe; 
配置config = ConfigurationManager.OpenExeConfiguration(appName);
ConnectionStringsSection section = config.GetSection( blabla as ConnectionStringsSection;





我获取有关当前应用程序(App.exe)的信息



现在,我需要修改OpenExeConfiguration方法或编写一个新的方法来读取我作为参数提供的配置文件..



希望,这一次明确了

解决方案

基本上没有。您可以打开任何文件,但不能假设ini文件存储在任何特定位置。一些与应用程序(旧式,.INI文件)或应用程序数据文件夹(更现代,通常但不一定基于XML)一起存储在注册表中(不再推荐,但它已经很长时间了,有些程序仍然可以),或在特定应用程序的地方(作者感觉的任何格式)。配置数据没有一种格式:它可以是作者想要的任何形式,包括人类可读和二进制文件。有些程序使用数据库...



没有配置文件的中央寄存器,因此没有可用于查找文件的通用字符串,更不用说了实际阅读文件内容并理解它们。


Hy there. I want to make an application that can modify any configuration file. I open a file dialog, select the file, populate some boxes with the information from the file, and lastly have a button "save information". Can I do this?

private void metroButton1_Click(object sender, EventArgs e)
       {
           OpenFileDialog openFileDialog1 = new OpenFileDialog();
           openFileDialog1.Filter = "Config Files|*.config";
           openFileDialog1.Title = "Slectează un fișier de configurări";
           if (openFileDialog1.ShowDialog() == DialogResult.OK)
           {
               textBox1.Text = openFileDialog1.FileName;
               filename = openFileDialog1.FileName;
           }
       }



string appName = "AdministrareRetele.exe";
            Configuration config = ConfigurationManager.OpenExeConfiguration(appName);
            ConnectionStringsSection section = config.GetSection("connectionStrings") as ConnectionStringsSection;




I don't know what to put at "ConfigurationManager"...

Thank you!

EDIT

I can get all the information I want from the configuration file of the CURRENT application. But I want to be able to get and modify info for other application.

Current scenario:

I have 2 files: App.exe and app.config in SAME folder. I write this code:

string appName = "App.exe";
            Configuration config = ConfigurationManager.OpenExeConfiguration(appName);
            ConnectionStringsSection section = config.GetSection("blabla") as ConnectionStringsSection;



and I get information about my current app (App.exe)

Now, I need to modify "OpenExeConfiguration" method or write a new one that will read a config file that i give as a parameter..

Hope, this time made it clear

解决方案

Basically, no. You can open any file, but you cannot assume that an ini file is stored in any particular place. Some are stored with the application (old style, .INI files) or in a app data folder (more modern, generally but not necessarily XML based), in the Registry (not recommended any more, but it was for a long time and some programs still do), or in a application specific place (in any format the author feels like). There is no "one format" for config data: it can be anythign the author wants, including human readable and binary files. Some programs use databases...

There is no "central register" of config files, so there is no general string you can include to locate the file, much less to actually read the file content and understand them.


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

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