winform 獲取相對路徑

//獲取相對路徑

 

//例如:System.Windows.Forms.Application.StartupPath = "F:\Sample_01\Material\bin\Debug"

//經過以下處理將返回"F:\Sample_01\Material\images\01.gif"

C#代碼  收藏代碼
  1. string path=System.Windows.Forms.Application.StartupPath + @"../../";   
  2. System.IO.Directory.SetCurrentDirectory(path);   
  3. string strFilePath = System.IO.Directory.GetCurrentDirectory() + @"\images\01.gif";  

 

 c#對文件和文件夾的操作主要用到的類是FileFileInfoDirectoryDirectoryInfo

其中FileInfoDirectoryInfo都是要實例化的

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