我的项目中有一个名为template.html
的文件,设置为“始终复制”。当我在本地运行api时,从Visual Studio执行File.ReadAllText("template.html")
我得到Could not find file 'C:\Program Files (x86)\IIS Express\template.html'.
显然,我可以在这里添加一个绝对路径,但这不是完全可移植的。如何使用相对路径访问我的文件?
编辑:我的代码是here。 LocalPefChartinator是主要的逻辑+ CLI,Test是测试,WebInterface是webapi位。
答案 0 :(得分:0)
由@MatíasFidemraizer发布的帖子帮助。
HostingEnvironment.MapPath("~/template.html")
如果我从Visual Studio运行,直接给我一个绝对路径。不知道当我在AppHarbor上运行它会发生什么,但它确实有效。