欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2023-12-19 21:23:34
废话不多说,直接上代码 /// /// 获得当前绝对路径 /// ...

废话不多说,直接上代码

/// <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# 获得当前绝对路径的方法(超简单)就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。

上一篇:

下一篇: