asp.net中各種路徑的獲取方法彙總

 
 

private void responsePath()
         {
             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 />");
             sb.Append(string.Format("獲取項目完整的絕對路徑: {0}", System.AppDomain.CurrentDomain.BaseDirectory.ToString()));
             sb.Append("<br />");
             //僅在嘗試向此域中加載程序集之後,此屬性纔可用
             sb.Append(string.Format("獲取項目,它由程序集衝突解決程序用來探測動態創建的程序集: {0}", System.AppDomain.CurrentDomain.DynamicDirectory));
             sb.Append("<br />");
             sb.Append(string.Format("獲取磁盤上指向應用程序目錄的物理路徑。: {0}", System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath));
             sb.Append("<br />");
             sb.Append(string.Format("獲取應用程序的虛擬根路徑: {0}", System.Web.Hosting.HostingEnvironment.ApplicationVirtualPath));
             sb.Append("<br />");
             sb.Append(string.Format("獲取站點的名稱。: {0}", System.Web.Hosting.HostingEnvironment.SiteName));
             sb.Append("<br />");
             //sb.Append(string.Format("獲取此應用程序的虛擬路徑提供程序。: {0}", System.Web.Hosting.HostingEnvironment.VirtualPathProvider));
             //sb.Append("<br />");
             sb.Append(string.Format("返回與 Web 服務器上的指定虛擬路徑相對應的物理文件路徑。: {0}", Server.MapPath("sss.aspx")));
             sb.Append("<br />");
             Response.Write(sb.ToString());
         }


string   s;  
   s="it's   here";  
   string   str=String.Format("You   can   see   {0}   and   you   see   {0}   again",s);  
   //now   str="You   can   see   it's   here   and   you   see   it's   here   again".   that's   usefully

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章