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);
The HTTP trigger lets you invoke a function with an HTTP request. You can use an HTTP trigger to build serverless APIs and respond to webhooks. The default return value for an HTTP-triggered function is: HTTP 204 No Content with an empty body in Functions 2.
ExecutionContext. The execution context enables interaction with the Azure Functions execution environment. HttpRequestMessage<T> An HttpRequestMessage instance is provided to Azure functions that use HttpTrigger.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With