System.Web.HttpContext.Current.Server.MapPath未将对象引用设置到对象的实例

2009年5月11日星期一

System.Web.HttpContext.Current.Server.MapPath未将对象引用设置到对象的实例

public static string MapPath(string strPath)
{
if (HttpContext.Current != null)
{
return HttpContext.Current.Server.MapPath(strPath);
}
else //非web程序引用
{
strPath = strPath.Replace("/", "\\");
if (strPath.StartsWith("\\"))
{
//strPath = strPath.Substring(strPath.IndexOf('\\', 1)).TrimStart('\\');
strPath = strPath.TrimStart('\\');
}
return System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, strPath);
}
}

    0 评论:

    发表评论