AppDomain.CurrentDomain.GetData(“DataDirectory”)始终返回Null

时间:2012-09-05 17:25:52

标签: c# sql-server-ce datadirectory

在我的程序中,我需要从默认位置复制模板数据库,据我所知,根据我选择使用的安装程序,它会有所不同。问题是我似乎无法读取| DataDirectory |的实际路径我知道我应该使用AppDomain.CurrentDomain.GetData(“DataDirectory”),但它总是在调试器中返回Null,这意味着我无法测试我的代码。我尝试了以下两种语法:

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

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

我做错了吗?

THANX!

1 个答案:

答案 0 :(得分:8)

尝试使用APPBASE

AppDomain.CurrentDomain.GetData("APPBASE")

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

如果您需要DataDirectory密钥,则必须在SetData

之前执行