Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Server.MapPath does not exist in the Current Context

Tags:

c#

.net

I have a C# Model Class where I am trying to access a .cshtml page which is supposed to be an email format template. I'm using the following code:

string body = string.Empty;
using (StreamReader reader = new StreamReader(Server.MapPath("~/EmailConfTemplate.cshtml")))
{
     body = reader.ReadToEnd();
}

But i am getting the following error message:

The name Server does not exist in the current context

Is there any error in the code or the Server class can't be accessed in POCO class. Please help.

like image 892
Lara Avatar asked Oct 14 '15 09:10

Lara


1 Answers

To execute it inside a .Net pipeline, you can find it as an instance present in HttpContext

System.Web.HttpContext.Current.Server.MapPath()
like image 161
Tushar Avatar answered Oct 24 '22 01:10

Tushar