2

I have a asp.net core project with angular template with below files structure.

enter image description here

I want to read the static HTML file (EmailConfirmation.html) from Template folder.

My code to read this file inside a controller as below.

string body = string.Empty;
using (StreamReader reader = new StreamReader("./Template/EmailConfirmation.html"))
{
body = reader.ReadToEnd();
}

But when I publish this app to azure, There is no folder created with the name Template inside wwwroot folder. Thus caught with an error

Something went wrong: System.IO.DirectoryNotFoundException: Could not find a part of the path 'D:\home\site\wwwroot\Template\EmailConfirmation.html'

For your note : I have tried with steps mentioned in the below article

https://learn.microsoft.com/en-us/aspnet/core/fundamentals/static-files?view=aspnetcore-2.2

But not worked out !

How can I solve this problem. Thanks for your attention. I’m looking forward to your reply.

Malatesh Patil
  • 4,505
  • 1
  • 14
  • 14

2 Answers2

3

Stratup.cs

public void Configure(IApplicationBuilder app)
{
     app.UseStaticFiles(new StaticFileOptions()
     {
        FileProvider = new 
        PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), @"Templete")),
                RequestPath = new PathString("/Templete")
     });
}

Controller Action

string body = string.Empty;
//using streamreader for reading my htmltemplate   
using (StreamReader reader = new StreamReader(Path.Combine("Templetes", "EmailConfirmation.html")))
{
   body = reader.ReadToEnd();
}
Rokive
  • 745
  • 9
  • 7
0

Try this:

using (var reader = File.OpenText(Path.Combine(@"./templates", $"{templateFileName}.html")))
        {
            return reader.ReadToEnd();
        }
hakantopuz
  • 481
  • 5
  • 11