我一直在使用ApplicationDeployment.CurrentDeployment.DataDirectory
来存储客户端在运行时下载的内容,预计每次启动应用程序时都会出现内容,但是现在如果应用程序更新,我发现这些更改看似随机。我可以在哪里安全地存储ClickOnce部署的数据文件?
什么是在点击一次部署中为应用程序存储用户数据的最可靠方法?
目前我一直在使用下面的方法
private const string LocalPath = "data";
public string GetStoragePath() {
string dir;
if (ApplicationDeployment.IsNetworkDeployed) {
ApplicationDeployment ad = ApplicationDeployment.CurrentDeployment;
dir = Path.Combine(ad.DataDirectory, LocalPath);
} else {
dir = LocalPath;
}
return CreateDirectory(dir);
}
我本来跟着标题下的ClickOnce Data Directory
文章Accessing Local and Remote Data in ClickOnce Applications其中指出,这是推荐路径。
注意:CreateDirectory(string)
只是创建一个目录,如果它不存在。
我发现我的问题的根本原因是我创建了许多文件和一个索引文件,这个索引文件包含绝对路径,一次性移动升级内容(或副本),所以绝对路径不复存在。我将调查独立存储,如Damokles所建议的,看看它是否对点击一次部署具有相同的副作用。
如果你走了孤立的存储路线,一定要看问题... http:// stackoverflow。com/questions/202013 – codeConcussion
谢谢whatknott,我会牢记这一点。 –