c# 获得当前绝对路径的方法(超简单)
时间:2021-04-22 09:11:52|栏目:.NET代码|点击: 次
废话不多说,直接上代码
/// <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);
}
}
栏 目:.NET代码
下一篇:js substr,substring与java substring和C# substring的区别解析
本文标题:c# 获得当前绝对路径的方法(超简单)
本文地址:http://www.codeinn.net/misctech/106407.html






