當類庫項目中無法使用Application.StartupPath的時侯 (注:主要是在進行反射讀取文件的時候!!)

http://jcserver.blog.163.com/blog/static/24044859200851582354135/

 

通常我們WinForm編程時,要獲取程序當 前運行的文件夾路徑會用Application.StartupPath ,但是Application.StartupPath在編寫類庫項目時卻無法 使用,因爲我們根本無法用using System.Windows.Forms;來引入Application.StartupPath 的命名空間,這個時侯我們要用AppDomain.CurrentDomain.BaseDirectory。

private static string fullPathFileName = Application.StartupPath + "//Set.Ini "; //用於WINFORM
private static string fullPathFileName = AppDomain.CurrentDomain.BaseDirectory+"//Set.Ini"; //用於類項目

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