Tuesday, September 7, 2010

A UI to edit/view config files for .NET Apps

Hello World,

I was wondering if I could provide my deployment team with a nice UI that would present app.config or web.config AppSettings section for viewing or editing. After some deliberation, I fired up my Visual Studio and started playing around with the methods of the Configuration class (found under the System.Configuration namespace). I noticed a method called OpenExeConfiguration that looked promising; it had all the methods that looked like having the ability to traverse the config file and read/write key value pairs.
Each discovery though comes with issues! I tried several ways of accessing the config file from another app but no matter what I tried, the HasFile method of Configuration class would return "false" indicating that there was no config file in the location I specified!! Then I began googling (what else would you do?!) and found this useful link: Blog Post
It appears that you need to tell the OpenExeConfiguration method where the EXE is and it will try to locate the config file by concatenating the exe name with ".config". E.g., if your exe is called MySuperApp.exe and could be found in the directory C:\, you would write something like this:

Configuration conf = ConfigurationManager.OpenExeConfiguration(@"C:\MySuperApp.exe");

Once I am through writing this UI app, I will try posting the code in this blog.

Until next time,
System.AllIsWell = true;
:)

1 comment:

  1. NOTE: For building a UI for web-apps, use OpenWebConfiguration method instead of OpenExeConfiguration.

    ReplyDelete