How to specify path in .config file relative to the file?

前端 未结 3 905
别跟我提以往
别跟我提以往 2021-02-19 18:49

An app I use interprets a .NET .config file. I added a line specifying the path to a certificate it needs



        
相关标签:
3条回答
  • 2021-02-19 19:03

    You can't change this just by changing the config file. Unless you use an absolute path.

    If you can change the application ...

    If this is an asp.net application, then use Server.MapPath. If it's a Windows app, you need to get the directory of the executing application and combine that with the relative path in your config file.

    System.Reflection.Assembly.GetExecutingAssembly().Location will give you the path to the .EXE file. You can then call Path.Combine to combine your relative path with the application's path.

    0 讨论(0)
  • 2021-02-19 19:06

    In visual studio 2015, the "~" keyword has no longer worked. You can now use :

    value="folder\subfoler"
    

    "folder" has the same level with .exe file

    0 讨论(0)
  • 2021-02-19 19:13

    By using the tilde

    value="~/certificate.abc"
    
    0 讨论(0)
提交回复
热议问题