加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 如何在类库项目中使用Server.MapPath

发布时间:2020-12-15 03:54:26 所属栏目:百科 来源:网络整理
导读:我有一个Web应用程序,它有一些类库项目.下面的一些示例代码. public static class LenderBL{ static string LenderXml { get { return "MyPathHere"; } } public static LenderColl GetLenders() { var serializer = new XmlSerializer(typeof(LenderColl));
我有一个Web应用程序,它有一些类库项目.下面的一些示例代码.
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);
        }
    }
}

我通常会使用Server.MapPath来获取属性LenderXml的路径,但是当我在类库中使用它时返回父解决方案的路径,而不是类库项目的路径.

有没有办法获得类自由项目本身的路径?

提前致谢.

解决方法

var Mappingpath = System.Web.HttpContext.Current.Server.MapPath("pagename.aspx");

希望它的帮助

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读