我在类中使用以下代码:
string filePath = HttpContext.Current.Server.MapPath("~/email/teste.html");
文件teste.html在文件夹中
但是当它打开文件时会生成以下错误:
Object reference not set to an instance of an object.
最佳答案
不要使用 Server.MapPath。它很慢。请改用 HttpRuntime.AppDomainAppPath
。只要您的网站在运行,此属性就始终可供您使用。
然后像这样使用它:
string filePath = Path.Combine(HttpRuntime.AppDomainAppPath, "email/teste.html");
关于c# - httpcontext.current.server.mappath 对象引用未设置为对象的实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6861368/