locked
relative path in App.config RRS feed

  • Question

  • I have following entry in App.config and I would like to use relative path. If I use absolute path it works fine.

    <enterpriseLibrary.ConfigurationSource selectedSource="File Configuration Source"
        <sources> 
          <add name="File Configuration Source" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common" 
           filePath="..\MyProject\EntLib.config" /> 
           
        </sources> 
      </enterpriseLibrary.ConfigurationSource>   


    And I got error:

    'Microsoft.Practices.EnterpriseLibrary.Logging.Logger' threw an exception. --->  System.IO.FileNotFoundException: The configuration file D:\develop\platforms\Microsoft Visual Studio 9.0\Common7\IDE\..\MyProject\EntLib.config 

    How do you set relative path in App.config

    Thanks in advance,
    Tom
    Friday, October 24, 2008 9:34 AM

Answers

  • No, sorry, there is nothing. When you run the program, it's not a project anymore - it's just another program.

    John Saunders | Use File->New Project to create Web Service Projects
    • Marked as answer by tomb_unaff Friday, October 24, 2008 6:12 PM
    Friday, October 24, 2008 6:10 PM
    Moderator

All replies

  • I'm sorry, but I can't read that. Please post it again.
    John Saunders | Use File->New Project to create Web Service Projects
    Friday, October 24, 2008 10:22 AM
    Moderator

  • I have Project folder & Unit Test project folder. In App.config in unit Test project I would like to refer to configuration file in Project folder(which is EntLib.config).
    I would like to use relative path. (Not absolute).
    But for relative path I cannot refer to EntLib.config

    This is App.config in TestProject Folder:

    <enterpriseLibrary.ConfigurationSource selectedSource="File Configuration Source"
        <sources> 
          <add name="File Configuration Source" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common" 
           filePath="..\MyProject\EntLib.config" /> 
           
        </sources> 
      </enterpriseLibrary.ConfigurationSource> 



    And when I run test I have this message:
    'Microsoft.Practices.EnterpriseLibrary.Logging.Logger' threw an exception. --->  System.IO.FileNotFoundException: The configuration file D:\develop\platforms\Microsoft Visual Studio 9.0\Common7\IDE\..\MyProject\EntLib.config

    How should I set relative path in filePath?
    Tom
    Friday, October 24, 2008 10:58 AM
  • Hi John,

    Don't know whats wrong but I hope you can read next post from me.
    If not let me know I will post it on another site and will provide a link.

    Tom
    Friday, October 24, 2008 11:01 AM
  • Does the file actually exist at the path stated by the exception?
    John Saunders | Use File->New Project to create Web Service Projects
    Friday, October 24, 2008 11:26 AM
    Moderator
  • No, there is no such file in  D:\develop\platforms\Microsoft Visual Studio 9.0\Common7\IDE\..\MyProject\

    I have EntLib.config  in D:\develop\projects\app\ScoreGame\MyProject\EntLib.config

    When I define absolute path like:
    filePath="D:develop\projects\app\ScoreGame\MyProject\EntLib.config" /> it is working fine.

    But I want to use relative path
    How should I define relative path?

    Thanks,
    Tom
    Friday, October 24, 2008 4:55 PM
  • A relative path is relative to the current default directory. Your path is fine. You just happen to be in a different default directory than you thought you would be. This is why you should stop trying to use a relative path - you don't know where you are, so how could you know hot to get where you want to be?
    John Saunders | Use File->New Project to create Web Service Projects
    Friday, October 24, 2008 5:23 PM
    Moderator
  • Doesn't exist variable which can be used to define position in file structure like:

    $(ProjectPath) or something similar?

    e.g.

    filePath="$(ProjectPath)\..\MyProject\EntLib.config" />

    This doesn't work for me, but maybe there is something that I can use? (I have tried: ~\  .\ , no results)

    Thanks,
    Tom
    Friday, October 24, 2008 6:03 PM
  • No, sorry, there is nothing. When you run the program, it's not a project anymore - it's just another program.

    John Saunders | Use File->New Project to create Web Service Projects
    • Marked as answer by tomb_unaff Friday, October 24, 2008 6:12 PM
    Friday, October 24, 2008 6:10 PM
    Moderator
  • Thanks John,

    Greetings,
    Tom
    Friday, October 24, 2008 6:24 PM