如何从c# /.net中的助手获取内容文件的路径
本文关键字:获取 路径 文件 net | 更新日期: 2023-09-27 18:16:08
这是我在VS 2012解决方案资源管理器中解决方案的结构:
abcWeb
- Properties
- References
- Service References
- App_Data
- Areas
- -abcArea
- - - Controlers
- - - - abcController
- - - ViewModels
- - - - abcViewModel
- - - Views
- - - - abcView
- Content
- - css
- - images
- - fonts
- - scripts
- - templates
- - - abc.html
- Globals
- Helpers
- - abcHelper.cs
. . .
我的问题是:
我有一个在abcHelper
中发送电子邮件的方法,该方法从内容/模板中读取abc.html文件,以包括作为电子邮件的正文。什么是路径作为一个字符串传递作为一个参数在System.IO.File.ReadAllText(...)
函数?
方法如下:
public void SendWelcomeTemplate()
{
string templatePath = @"../Content/templates/abc.html"; // This doesn't work!
var emailBody = System.IO.File.ReadAllText(templatePath);
SendEmail(strToEmailAddress, strEmailSubject, emailBody);
}
我非常感谢你的帮助
试试这个;
string templatePath = Server.MapPath("/Content/templates/abc.html");