Getting current config file path

Topics: Building and extending application blocks, General discussion
Jul 30, 2010 at 7:43 PM
I need to get a reference to the console host's configuration source, specifically the configuration file, for use in reading data from non-ent lib config sections (e.g. system.servicemodel). How can I get to this information from a custom editor?
Aug 2, 2010 at 3:06 AM

Use Environment.CurrentDirectory combining with the name of the configuration file.  For non-entlib questions, please post in the other .NET forums.


Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.

Aug 2, 2010 at 4:03 AM

Let me re-phrase - the configuration source the console host has loaded, i.e. not the host executable's configuration file, but the one the user is editing. A little clearer now?

Aug 2, 2010 at 5:30 AM

If the config is already loaded in the editor, then surely the path of that config file has already been retrieved before and passed to the editor, right?  This looks like a non-entlib question, please post it in other forums.

Aug 2, 2010 at 3:26 PM

When you select File->Open and open the the file, group policy, what have you - that is the file or configuration source I'm not looking for, not the one associated with the appdomain of the host. I'm really not sure what more can be added here to clarify - this is a pretty basic question.

Aug 3, 2010 at 3:49 AM

Hmm so is it correct that what are you pertaining is the file path of the config file that is loaded and being updated in your custom editor, right? If yes, then haven't you already know the file path value of that config file given that you have actually already been able to load it in your custom editor? Sorry, but I'm afraid your question still seems confusing to me. One suggestion I can give is exploring the File/FileInfo Class of System.IO namespace if it may have something that will be helpful with your needs. Though, as also mentioned by my colleague this looks like a non-entlib inquiry and you may get better answers from other .NET forums.

Gino Terrado
Global Technology and Solutions
Avanade, Inc.

Aug 3, 2010 at 4:04 AM

Let's try this yet another way...

1.) Custom editor != an application, it's a WPF control that's used to edit a configuration item not a configuration file. For example, the database connection editor or others. In other words, it's what's created when you specify the EditorType (or whatever) attribute on a setting. I need to access the file that's loaded by the console (or actually the configuration source, although that has a number of limitations due to poor design) to validate something in a configuration section that's outside of the EntLib supported sections.

2.) No - you don't have access to this file, only the host and its services have this readily available and it's exposed through IApplicationService. Without a reference to IApplicationService, there's no way to get the file or configuration source.

3.) A hack is provided here: This is hopefully not the correct solution as this is a pretty ugly way to accomplish what I'm after. I assume there's a more correct way, however providing rich integration into the configuration console is (still) not documented remotely well.

I'm truly beyond words if this doesn't clarify the issue sufficiently.

Aug 3, 2010 at 8:02 AM

See this other forum thread if it may be any help on reading the service model section from a config


Aug 3, 2010 at 1:39 PM

Wow...4 tries and you still aren't understanding. I'm well aware of how to read information from a configuration file. Did you even read the article I posted to see how it's obtaining the file the configuration console has loaded? I'm asking for a more appropriate way to get the reference to IApplicationService which provides the file loaded by the editor. This is NOT the host's configuration file.

My how Avanade's hiring practices have fallen.

Aug 4, 2010 at 10:29 AM
Edited Aug 4, 2010 at 10:29 AM

Ok, we do understand the problem now that we got more info.  In the source code, the remarks for the IApplicationModel interface says that "In order to get an instance of this interface, declare it as a constructor argument on the consuming component or use the <see cref="IUnityContainer"/> to obtain an instance from code."  However, I haven't successfully injected the IApplicationModel instance to a custom editor it since they are created via the EditorAttribute and has no knowledge on dependency injection.  We're still looking into this and digging into the source code.  We'll let you know once we have an update.


Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.

Aug 5, 2010 at 7:41 PM

Nate, hello

We don't expose access to the file directly. The approach you described in your blog post does seem awkward.

The new config tool is meta-data driven. The way we intended it to work is to attribute stuff. Today, we don’t have EntLib Extensibility documentation available yet (though it is in our product backlog and we will also be doing a workshop dedicated to this topic at the p&p symposium).

To give you an example of how your scenario can be accomplished, I can recommend the Unity configuration tool extension, the prototype of which is available as part of Beta1.

Please take a look and see if it helps. If it doesn’t, feel free to ping me directly.

Also, I'll be happy to discuss your scenarios further and suggestions for alternative extension points which we may implement in the next version of EntLib.



Aug 5, 2010 at 8:59 PM
Thanks - I'll give it a look this weekend. I may be at the P&P summit so I look forward to that if so!