如何从C#/ .net中的Helpers的Content文件中获取路径

时间:2014-08-01 09:26:53

标签: c# .net asp.net-mvc-4

这是我在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);
    }

我非常感谢任何帮助。

1 个答案:

答案 0 :(得分:1)

试试这个;

string templatePath = Server.MapPath("/Content/templates/abc.html");