2016-02-26 68 views
3

我下面的代码给本地路径如何映射路径分配在C#中的字符串,MVC

using (StreamReader reader = new StreamReader(Server.MapPath("~/EmailStyle/TD-emailForCus.html"))) 
      { 
       body = reader.ReadToEnd(); 
      } 

连接发送邮件与我的网站project.I然后使用这个作品properly.but我想要这样做。

stirng mypath = stirng.Format("~/EmailStyle/TD-emailForCus.html"); 
using (StreamReader reader = new StreamReader(Server.MapPath(mypath))) 
       { 
        body = reader.ReadToEnd(); 
       } 

当我这样做,它不能正常工作,可以给我一个像这样的地图路径。你的help.thanx。

+0

什么是错误? – rt2800

+0

当我在流读取器行中使用断点时。它通过它。但后来执行被停止.. – mithu

回答

2

不喜欢this.get完整Server.MapPath()到这样一个变量,然后调用它,

var mypath = Server.MapPath("~/EmailStyle/TD-emailForCus.html"); 
using (StreamReader reader = new StreamReader(mypath)) 
      { 
       body = reader.ReadToEnd(); 
      } 

这将帮助你。