How can I use Server.MapPath inside class library project

dotnetnoob picture dotnetnoob · Apr 15, 2013 · Viewed 51.5k times · Source

I have a web application thet has a number of class library projects. Some example code below.

public static class LenderBL
{
    static string LenderXml { get { return "MyPathHere"; } }

    public static LenderColl GetLenders()
    {
        var serializer = new XmlSerializer(typeof(LenderColl));

        using (XmlReader reader = XmlReader.Create(LenderXml))
        {
            return (LenderColl)serializer.Deserialize(reader);
        }
    }
}

I would normally use Server.MapPath to get the path for the property LenderXml, but when I use it in a class library is returns the path of the parent solution, not that of the class library project.

Is there a way of getting the path for the class libary project itself?

Thanks in advance.

Answer

Freelancer picture Freelancer · Apr 15, 2013
    var Mappingpath = System.Web.HttpContext.Current.Server.MapPath("pagename.aspx");

Hope its helpful.