Relative file path in filepath

Topics: Enterprise Library Core, General discussion
May 26, 2010 at 2:27 PM

Hello,  

I am using an external EntLib.config file to store all my enterprise library related config settings. The EntLib.config is in the same folder as the web.config.

The following is from the web.config : 

 

<enterpriseLibrary.ConfigurationSource selectedSource="File-based Configuration Source">
    <sources>
      <add name="File-based Configuration Source" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                 filePath="C:\<folder>\<folder>\<folder>\<folder>\EntLib.config" /> 
    </sources>
    <redirectSections>
      <add sourceName="File-based Configuration Source" name="connectionStrings" />
      <add sourceName="File-based Configuration Source" name="exceptionHandling" />
      <add sourceName="File-based Configuration Source" name="loggingConfiguration" />
    </redirectSections>
  </enterpriseLibrary.ConfigurationSource>

 

Is there a way to specify the filepath using a relative path? I tried the following:

 

filePath="EntLib.config"

 

 filePath="..\EntLib.config"

 

but both times I get a 'The configuration file EntLib.config could not be found.' exception on my Logger.Write() method.

 

Thank you in anticipation.

May 27, 2010 at 11:30 AM

Hi firozjokhi,

Both relative path (EntLib.config and ..\EntLib.config) should work, you just need to make sure that your config exist in that directory.

For "EntLib.config" it is looking the config file in the same directory of your executable file i.e. bin\Debug if in debug mode in VS while for the "..\EntLib.config" it is VS\Projects\<Solution Folder>\.

HTH,

Gino Terrado
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

May 27, 2010 at 2:15 PM

Hello and thank you for your reply.

I most definitely have the EntLib.config in the same directory as the web.config. Also, I have set its property to 'Copy always to Output directory'. Nevertheless I keep getting the 'The configuration file EntLib.config could not be found.' error.

Is there a way to test whats going wrong? What directory is it trying to look into?

Thank you again

 

May 27, 2010 at 4:08 PM

Hmm..are you sure the logging was configured properly in your Entlib.config? Try testing first if the logging would work properly if it is in the web.config.

As for the directory of the relative path it tries to look into as of now I can't think of anything else but you can try using the FileInfo class in your App as a test code to supply the same relative path you are using in the FileConfigurationSource to exactly determine the location of which the relative path looks into (FileInfo d = new FileInfo(@"..\External.config");).

Gino Terrado
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

May 27, 2010 at 4:51 PM

Thank you again for your quick reply.

Yes, the Ent Lib configurations work just fine when I place them in the web.config. But I need to move them in the EntLib.config to have a simple web.config.

I tried placing this line right before the Logger.Write() method : 

Dim d As System.IO.FileInfo = New System.IO.FileInfo("EntLib.config") and it shows directory as {C:\Program Files\Common Files\Microsoft Shared\DevServer\10.0}

While 

Dim d As System.IO.FileInfo = New System.IO.FileInfo("EntLib.config") shows directory as {C:\Program Files\Common Files\Microsoft Shared\DevServer}

Obviously, that is not where I have the EntLib.config. So how do I point in the right directory using a relative path? And why does it point to the directory it is pointing to now?

Thanks!

 

 
May 27, 2010 at 6:49 PM

Sorry I've missed the fact the it was a web application. The reason why it was pointing to C:\Program Files\Common Files\Microsoft Shared\DevServer is because you are currently running the web app in the dev server.

If you want something like "C:\<folder>\<folder>\<folder>\<folder>\EntLib.config",  I think using this will work "\..\<folder>\<folder>\<folder>\EntLib.config".  

Gino Terrado
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

May 27, 2010 at 7:43 PM

Hey again,

I tried a Dim d As System.IO.FileInfo = New System.IO.FileInfo("\..\EntLib.config") but that tries to look at C:\EntLib.config
A Dim d As System.IO.FileInfo = New System.IO.FileInfo("~\..\EntLib.config") goes back to looking at C:\Program Files\Common Files\Microsoft Shared\DevServer

So I don't think that will work. I need a relative path so I can just put a "Entlib.config" or something and it points to the Entlib.config in the same folder as my web.config.

Any more suggestions?

Thanks

May 28, 2010 at 5:01 AM

This was logged in the Issue Tracker - http://entlib.codeplex.com/WorkItem/View.aspx?WorkItemId=26760

Currently, the only workaround is to modify the source code which is also posted in the workitem, or use the 4.1 version if that is an option for you.

 

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Aug 17, 2010 at 4:02 PM
Change the property "Copy to Output Directory" on EntLib.config to "Copy if newer". The default is "do not copy". So the file really doesn't exist.