虛擬路徑和物理路徑的轉化

//本地路徑轉換成URL相對路徑  
private string urlconvertor(string imagesurl1)
        {
            string tmpRootDir = Server.MapPath(System.Web.HttpContext.Current.Request.ApplicationPath.ToString());//獲取程序根目錄
            string imagesurl2 = imagesurl1.Replace(tmpRootDir, ""); //轉換成相對路徑
            imagesurl2 = imagesurl2.Replace(@"\", @"/");
            //imagesurl2 = imagesurl2.Replace(@"Aspx_Uc/", @"");
            return imagesurl2;
        }
        //相對路徑轉換成服務器本地物理路徑  
        private string urlconvertorlocal(string imagesurl1)
        {
            string tmpRootDir = Server.MapPath(System.Web.HttpContext.Current.Request.ApplicationPath.ToString());//獲取程序根目錄 
            string imagesurl2 = tmpRootDir + imagesurl1.Replace(@"/", @"\"); //轉換成絕對路徑 
            return imagesurl2;
        }

 

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