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

前端 未结 3 889
别跟我提以往
别跟我提以往 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.

提交回复
热议问题