当前位置: 移动技术网 > IT编程>开发语言>c# > c# 获得当前绝对路径的方法(超简单)

c# 获得当前绝对路径的方法(超简单)

2019年07月18日  | 移动技术网IT编程  | 我要评论

废话不多说,直接上代码

/// <summary>
    /// 获得当前绝对路径
    /// </summary>
    /// <param name="strpath">指定的路径</param>
    /// <returns>绝对路径</returns>
    public static string getmappath(string strpath)
    {
      if (strpath.tolower().startswith("http://"))
      {
        return strpath;
      }
      if (httpcontext.current != null)
      {
        string path = httpcontext.current.server.mappath("~/" + strpath);
        return path;
      }
      else //非web程序引用
      {
        strpath = strpath.replace("/", "\\");
        if (strpath.startswith("\\"))
        {
          strpath = strpath.substring(strpath.indexof('\\', 1)).trimstart('\\');
        }
        return system.io.path.combine(appdomain.currentdomain.basedirectory, strpath);
      }
    }

以上这篇c# 获得当前绝对路径的方法(超简单)就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持移动技术网。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网