I have a class libary project (NotificationTemplate) which return content of file:
public static class Template
{
    public static string NotificatioEmail
    {
        get { return File.ReadAllText("Templates\\NotificatioEmail.cshtml"); }
    }
}
In this project is located folder Templates with NotificatioEmail.cshtml file.  
Also, I have two application: console app and ASP.NET MVC app. The file returned fine in the console app, but in the MVC I get error file not found. How to write universally?
I tryed this:
Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "Templates",
             "NotificatioEmail.cshtml")
but BaseDirectory don't include bin folder.
As you said BaseDirectory works for console apps. For MVC applications, use RelativeSearchPath instead.
So you can use this code for both platforms
var appDomain = System.AppDomain.CurrentDomain;
var basePath = appDomain.RelativeSearchPath ?? appDomain.BaseDirectory;
Path.Combine(basePath, "Templates", "NotificatioEmail.cshtml");
                        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