Getting html file from path for an Azure Function

Viewed 4394

I have a html file that is an email template. In my Azure function I want to read the file in with 'HtmlDocument', manipulate it, then send it out as an email to members.

How do I read the file 'hero.html' from my Azure Function app? And then once I publish it to Azure will I need to change the way the file is read?

FYI - doc.Load accepts a string, file path and other parameters

Here is what I tried and a pic of my project.

        //var emailBodyText = File.ReadAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Templates", "hero.html"));
        var mappedPath = Path.GetFullPath("hero.html");

        var doc = new HtmlDocument();
        doc.Load(mappedPath);

enter image description here

1 Answers

You can get the function directory name from ExecutionContext parameter, if you add it to the function:

public static HttpResponseMessage Run(HttpRequestMessage req, ExecutionContext context)
{
    var path = $"{context.FunctionDirectory}\\Templates\\hero.html";
    // ...
}

See details in Retrieving information about the currently running function.

Related