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

前端 未结 6 2667
清歌不尽
清歌不尽 2021-02-19 18:44

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



        
6条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-19 19:18

    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.

提交回复
热议问题