抓取 WinForm 應用程式所在的目錄可使用下面方法,此方法會回傳應用程式設定輸出目錄完整路徑。
1 | System.Windows.Forms.Application.StartupPath |
抓取 Console 應用程式所在的目錄可使用下面方法。
1 | System.AppDomain.CurrentDomain.BaseDirectory; |
抓取 ASP.NET 網頁程式,所在的目錄可用下面方法。
若是要包成 Library 呢? 以上皆適用。
1 | System.AppDomain.CurrentDomain.BaseDirectory; |
補充 :
01 | protected void Page_Load( object sender, EventArgs e) { |
04 | Response.Write( "Server.MapPath : " + Server.MapPath( "~" ) + "<br />" ); |
07 | Response.Write( "Server.MapPath : " + Server.MapPath( "." ) + "<br />" ); |
10 | Response.Write( "Request.ApplicationPath : " + Request.ApplicationPath + "<br />" ); |
13 | Response.Write( "Request.CurrentExecutionFilePath : " + Request.CurrentExecutionFilePath + "<br />" ); |
16 | Response.Write( "Request.FilePath : " + Request.FilePath + "<br />" ); |
19 | Response.Write( "Request.Path : " + Request.Path + "<br />" ); |
22 | Response.Write( "Request.PhysicalApplicationPath : " + Request.PhysicalApplicationPath + "<br />" ); |
25 | Response.Write( "Request.PhysicalPath : " + Request.PhysicalPath + "<br />" ); |
輸出結果
沒有留言:
張貼留言