开发者

How to pass relative path in appsetting

i have following code and when i pass absolute path my project works but i need relative path configuration.ini is a file which is in my current project so when i give absolute path, like this ,the code never runs

<app Settings
 <add key="Configuration Path"    value="d:DocsWcfService\Configuration.INI"/>
    </app Settings

i need something like this ,is there any way?

<app Settings
 <add key="Configuration Path"    valu开发者_如何学Goe="~\Configuration.INI"/>
</app Settings


Server.MapPath

var physicalPath = Server.MapPath("~\Configuration.ini");


I had the same problem for config file before. I was able to use full path and it was working fine. When I try to use relative path , it wasn't able to find my config file. I hope my solution helps you or at least give you an idea.

Try to click file located in the solution expllorer and expand the properties tab to change 'copy to output directory' as 'Copy Always' . As I know VS copy to file to \bin\Debug folder every time when we run the project, so the relative path of that file will always be the same during development as well as after deployment.

After that below code will be enough

<app Settings
     <add key="Configuration Path"    value="Configuration.INI"/>
</app Settings
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜