I've an ASP.NET MVC project that has a sub folder called emails. This contains HTM files for my email templates. At certain points in the site, I have a controller that needs to load one of these templates and send it as an email.
What I'm trying to do is use reflection to get the path of the current executing assembly but it's not working as I would expect it. The path I am getting back is:
var directory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
'C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET iles\ssl\1da130c4\f8e7810e\assembly\dl3\5f253aca\1a71f123_e83bcc01\Emails\ProductAccountConfirmation.htm'
I find this strange as the site is being hosted in IIS via Visual Studio. I would have thought this would give me the dll location in my project folder in dev and the deploy folder for IIS in production.
What you are looking for is Server.MapPath(), it will give you the path of the application that you are executing.
So let's say you have a file called template1.html in your emails sub-folder. This code should give you the full path of that HTML file.
HttpContext.Current.Server.MapPath("/") + "\\emails\\template1.html";
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