虚位以待(AD)
虚位以待(AD)
首页 > 软件编程 > C#编程 > c# 获得当前绝对路径的方法(超简单)

c# 获得当前绝对路径的方法(超简单)
类别:C#编程   作者:码皇   来源:互联网   点击:

下面小编就为大家分享一篇c 获得当前绝对路径的方法(超简单),具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧

废话不多说,直接上代码

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

您可能感兴趣的文章:

  • ASP.NET总结C#中7种获取当前路径的方法
  • C#实现获取程序路径方法小结
  • 相对路径和绝对路径的写法总结
  • C#获取路径的几种方式实例分析
  • C#使用浏览按钮获得文件路径和文件夹路径的方法
相关热词搜索: c 当前 绝对路径