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

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

作者:jingxian  发布时间:2021-06-18 05:23:31 

标签: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);
     }
   }

来源:http://www.cnblogs.com/highest/p/8301376.html

0
投稿

猜你喜欢

手机版 软件编程 asp之家 www.aspxhome.com