1

I've got a .net core lambda function.

Within the function i've got a folder called Content with a html file in there.

Is there anyway to read that file from the function? If so what is the path?

I've got this:

var message = string.Empty;
using (var sr = new StreamReader("/Content/email.html"))
{
  message = sr.ReadToEnd();
}

But that gives:

Could not find a part of the path '/Content/email.html'.

Thanks

2 Answers 2

3

Have you used AppDomain.CurrentDomain.BaseDirectory to get the directory your function is executed from.

eg:

var basePath = AppDomain.CurrentDomain.BaseDirectory;
var filePath = "/Content/email.html"
var finalPath= Path.Combine(basePath, filePath); 
Sign up to request clarification or add additional context in comments.

1 Comment

does this work for a Lambda function?
1

If you are deploying, right click the file in your solution explorer, click properties. Make sure to change the "Copy to output directory" to "copy always"

Comments

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.