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

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

发布时间:2020-12-15 01:03:25 所属栏目:C语言 来源:网络整理
导读:废话不多说,直接上代码 /// summary /// 获得当前绝对路径 /// /summary /// param name="strPath"指定的路径/param /// returns绝对路径/returns public static string GetMapPath(string strPath) { if (strPath.ToLower().StartsWith("http://")) { retu

废话不多说,直接上代码

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

您可能感兴趣的文章:

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

(编辑:李大同)

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

    推荐文章
      热点阅读