我正在发送带有我的 Web 项目的附件邮件。我使用以下代码提供本地路径
using (StreamReader reader = new StreamReader(Server.MapPath("~/EmailStyle/TD-emailForCus.html")))
{
body = reader.ReadToEnd();
}
那么这就可以正常工作了。但我想这样做。
stirng mypath = stirng.Format("~/EmailStyle/TD-emailForCus.html");
using (StreamReader reader = new StreamReader(Server.MapPath(mypath)))
{
body = reader.ReadToEnd();
}
当我这样做时,它无法正常工作。我怎样才能给出这样的 map 路径。希望得到你的帮助。谢谢。
最佳答案
这样做。将完整的 Server.MapPath()
赋给这样的变量,然后调用它,
var mypath = Server.MapPath("~/EmailStyle/TD-emailForCus.html");
using (StreamReader reader = new StreamReader(mypath))
{
body = reader.ReadToEnd();
}
这对你有帮助。
关于c# - 如何在c#、mvc中为字符串分配映射路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35645096/