现在的位置: 首页 > 综合 > 正文

.Net中获取当前路径的方法

2013年04月29日 ⁄ 综合 ⁄ 共 361字 ⁄ 字号 评论关闭

//Web编程

  1. HttpContext.Current.Server.MapPath("FileName")
  2. System.Web.HttpContext.Current.Request.Path

TextBox1.Text = System.Web.HttpContext.Current.Server.MapPath("");

或是

TextBox1.Text = System.Web.HttpContext.Current.Server.MapPath("~");

 

ASP.NET 会将 ~ 运算符解析为当前应用程序的根目录。

返回结果不带/,如下

D:/我的文档/Visual Studio 2008/WebSites/WebSite1/scripts

  1. //Windows编程
  2. System.Environment.CurrentDirectory

抱歉!评论已关闭.