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

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

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

  2021-03-28 我要评论
想了解c# 获得当前绝对路径的方法(超简单)的相关内容吗,在本文为您仔细讲解c# 获得当前绝对路径的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点: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# 获得当前绝对路径的方法(超简单)就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。

猜您喜欢

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们