我想调用System.Web.HttpContext.Current.Server.MapPath("strMath"),可是提示错误,系统找不到该文件,如果我的文件是放在C:\windosw下,那这段代码该怎样写System.Web.HttpContext.Current.Server.MapPath("strMath"),注意是线程Thread调用。

解决方案 »

  1.   

    你是在asp.net程序里调用了这个么?
      

  2.   

    我是在cs里面写这个,怎样在cs里面使用这个获取应用程序根目录的路径?
      

  3.   

    自定义一个方法
    public static string MapPath(string strPath)
            {
                if (System.Web.HttpContext.Current != null)
                {
                    return System.Web.HttpContext.Current.Server.MapPath(strPath);
                }
                else //非web程序引用
                {
                    strPath = strPath.Replace("/", "");
                    strPath = strPath.Replace("~", "");
                    if (strPath.StartsWith("\\"))
                    {
                        strPath = strPath.TrimStart('\\');
                    }
                    return System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, strPath);
                }
            }