httpcontext.current.server.mappath Object reference not set to an instance of an object

Don’t use Server.MapPath. It’s slow. Use this instead, HttpRuntime.AppDomainAppPath. As long as your web site is running, this property is always available to you.

Then use it like this:

string filePath = Path.Combine(HttpRuntime.AppDomainAppPath, "email/teste.html");

Leave a Comment