我是靠谱客的博主 呆萌白猫,这篇文章主要介绍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# 获得当前绝对路径的方法(超简单)就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持靠谱客。

最后

以上就是呆萌白猫最近收集整理的关于c# 获得当前绝对路径的方法(超简单)的全部内容,更多相关c#内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(185)

评论列表共有 0 条评论

立即
投稿
返回
顶部