获取项目完整的绝对路径
string path = System.AppDomain.CurrentDomain.BaseDirectory.ToString();
string path = Server.MapPath(".");//此"."可以换成项目文件里的其它文件夹名称
 
输出asp.net 网站路径
private void responseHtml()
 {
        System.Text.StringBuilder sb = new System.Text.StringBuilder();
        sb.Append(string.Format("当前时间: {0}", Server.HtmlEncode(DateTime.Now.ToString())));
        sb.Append("<br />");
        sb.Append(string.Format("当前请求的虚拟路径: {0}",Server.HtmlEncode(Request.CurrentExecutionFilePath)));
        sb.Append("<br />");
        sb.Append(string.Format("获取当前应用程序的根目录路径: {0}", Server.HtmlEncode(Request.ApplicationPath)));
        sb.Append("<br />");
        sb.Append(string.Format("当前请求的虚拟路径: {0}",Server.HtmlEncode(Request.FilePath)));
        sb.Append("<br />");
  sb.Append(string.Format("当前请求的虚拟路径: {0}",Server.HtmlEncode(Request.Path)));
        sb.Append("<br />");
        sb.Append(string.Format("获取当前正在执行的应用程序的根目录的物理文件系统路径: {0}", Server.HtmlEncode(Request.PhysicalApplicationPath)));
        sb.Append("<br />");
        sb.Append(string.Format("获取与请求的 URL 相对应的物理文件系统路径: {0}", Server.HtmlEncode(Request.PhysicalApplicationPath)));
        sb.Append("<br />");
        Response.Write(sb.ToString());
}

输出:当前时间: 2008-11-7 10:26:47
当前请求的虚拟路径: /test/Gauge.aspx
获取当前应用程序的根目录路径: /test
当前请求的虚拟路径: /test/Gauge.aspx
当前请求的虚拟路径: /test/Gauge.aspx
获取当前正在执行的应用程序的根目录的物理文件系统路径: D:\Asp.net测试项目\test\
获取与请求的 URL 相对应的物理文件系统路径: D:\Asp.net测试项目\test\

获取项目完整的绝对路径
string path = System.AppDomain.CurrentDomain.BaseDirectory.ToString();
string path = Server.MapPath(".");//此"."可以换成项目文件里的其它文件夹名称
 
输出asp.net 网站路径
private void responseHtml()
 {
        System.Text.StringBuilder sb = new System.Text.StringBuilder();
        sb.Append(string.Format("当前时间: {0}", Server.HtmlEncode(DateTime.Now.ToString())));
        sb.Append("<br />");
        sb.Append(string.Format("当前请求的虚拟路径: {0}",Server.HtmlEncode(Request.CurrentExecutionFilePath)));
        sb.Append("<br />");
        sb.Append(string.Format("获取当前应用程序的根目录路径: {0}", Server.HtmlEncode(Request.ApplicationPath)));
        sb.Append("<br />");
        sb.Append(string.Format("当前请求的虚拟路径: {0}",Server.HtmlEncode(Request.FilePath)));
        sb.Append("<br />");
  sb.Append(string.Format("当前请求的虚拟路径: {0}",Server.HtmlEncode(Request.Path)));
        sb.Append("<br />");
        sb.Append(string.Format("获取当前正在执行的应用程序的根目录的物理文件系统路径: {0}", Server.HtmlEncode(Request.PhysicalApplicationPath)));
        sb.Append("<br />");
        sb.Append(string.Format("获取与请求的 URL 相对应的物理文件系统路径: {0}", Server.HtmlEncode(Request.PhysicalApplicationPath)));
        sb.Append("<br />");
        Response.Write(sb.ToString());
}

输出:当前时间: 2008-11-7 10:26:47
当前请求的虚拟路径: /test/Gauge.aspx
获取当前应用程序的根目录路径: /test
当前请求的虚拟路径: /test/Gauge.aspx
当前请求的虚拟路径: /test/Gauge.aspx
获取当前正在执行的应用程序的根目录的物理文件系统路径: D:\Asp.net测试项目\test\
获取与请求的 URL 相对应的物理文件系统路径: D:\Asp.net测试项目\test\

相关文章:

  • 2022-02-07
  • 2021-09-30
  • 2022-02-07
  • 2021-11-27
  • 2021-11-29
  • 2022-02-07
  • 2021-12-07
猜你喜欢
  • 2021-12-23
  • 2022-12-23
  • 2021-12-09
  • 2021-12-19
  • 2021-07-05
  • 2021-11-27
相关资源
相似解决方案