ASP.NET MVC Reading Files from the Server

I have 3 questions:

  • Where is the location for some template files? I will use these templates to render emails with DotLiquid . I'm thinking of just having it in ~/Templates/.
  • How do I unit test this? Should I even unit test read files from the file system?
  • Best way to read a file in a line?
+3
source share
3 answers
  • I would make a browsing folder /Views/Emailspossible for them
  • Unit test code you are writing, not code from the .NET framework imo
  • string s = System.IO.File.ReadAllText( path );
+4
source

Placing the code in ~ / Content / Templates / and loading the content using the web client worked best for me.

var welcomeMailTemplatePath = "yourPath";
var webClient = new WebClient();
string html = webClient.DownloadString(WelcomeMailTemplatePath); 

This way you do not need to deal with controllers / views and can directly capture the contents of a template file.

0
source

Source: https://habr.com/ru/post/1791780/


All Articles