Search code examples
c#model-view-controllersmtpserver.mappath

How to assign a map path to a string in c#, mvc


I'm sending attached mail with my web project.I use following code to give the local path

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

then this works properly.but I want to do like this.

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

when I do this, it does not work properly.how can I give a map path like this.hope your help.thanx.


Solution

  • do like this.get your full Server.MapPath() to a variable like this and then call it,

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

    this will help to you.