RaelB RaelB - 11 months ago 59
C# Question

How to load a file into a string in asp.net mvc

I am sending some email in an asp.net mvc application, and I want to place some html templates in a folder.

If I place a template file in a folder under Models e.g.

how do I load this file into a string (to be later used as the email body). I want to use
. How do I reference the file location?

Answer Source
string path = "~/Models/EmailTemplates/MyTemplate.html";
string html = System.IO.File.ReadAllText(System.Web.HttpContext.Current.Server.MapPath(path));

Use Server.MapPath