Click here to Skip to main content
15,909,953 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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?

C#
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;
           }
       }


C#
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:

C#
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
Posted
Updated 19-Jun-13 3:10am
v2

1 solution

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.
 
Share this answer
 
Comments
Luci C 19-Jun-13 9:10am    
I improved the original question..

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