2

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. Models\EmailTemplates\MyTemplate.html how do I load this file into a string (to be later used as the email body). I want to use System.IO.File.ReadAllText. How do I reference the file location?

1 Answer 1

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

Use Server.MapPath

Sign up to request clarification or add additional context in comments.

3 Comments

Server.MapPath works by itself. However, VS 2015 could not resolve HttpContext.Current (I am calling from within a Controller action)
Added namespace before HttpContext to resolve it. Check now
Good. Happy to help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.