我有一个VS 2012 Web服务项目,其中包括一个名为myconfig.xml的文件,我已经将复制操作属性设置为“始终复制”。
我尝试用以下行加载XML文件:
doc.Load("myconfig.XML");但是,ASP.net引发异常,因为它无法从C:\program (x86)\IIS 7读取该文件。
我试过这个:
System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);但是它返回到临时目录的路径,如何获得myconfig.XML的实际位置?
发布于 2013-11-18 21:58:06
在ASP.NET中,您应该始终使用Server.MapPath
// root folder
var docPath = Server.MapPath("/doc.xml");
// some other folder
var docPath = Server.MapPath("/folder/doc.xml");发布于 2013-11-18 21:37:40
应该是
Environment.CurrentDirectory在web环境中,您可以使用AppDomain来计算目录。
AppDomain.CurrentDomain.BaseDirectory发布于 2013-11-18 21:42:15
https://stackoverflow.com/questions/20058435
复制相似问题