2012-09-05 175 views
4

在我的程序中,我需要從默認位置複製一個模板數據庫,根據我選擇使用的安裝程序,我知道它會有所不同。問題是,我似乎無法讀取| DataDirectory |的實際路徑我知道我應該使用AppDomain.CurrentDomain.GetData(「DataDirectory」),但它始終在調試器中返回Null,這意味着我無法測試我的代碼。我試過以下兩種語法:AppDomain.CurrentDomain.GetData(「DataDirectory」)總是返回空

string sourcePath = AppDomain.CurrentDomain.GetData("DataDirectory").ToString(); 

string defaultpath = Convert.ToString(AppDomain.CurrentDomain.GetData("DataDirectory")); 

難道我做錯了什麼?

ThanX!

回答

8

與應用平臺

嘗試
AppDomain.CurrentDomain.GetData("APPBASE") 

http://msdn.microsoft.com/en-us/library/system.appdomainsetup.applicationbase.aspx

如果你想之前SetData

+0

謝謝您必須執行DataDirectory關鍵。只是爲了確認,據我瞭解,數據庫可以根據它的打包方式存儲在不同的位置。我知道調試把它放在應用程序文件夾中,但是如果它像ClickOnce一樣部署,數據庫可以在一個子文件夾中,而且MSI可以完全做其他事情。 –