我在哪里可以安全地存储ClickOnce部署的数据文件? [英] Where can I safely store data files for a ClickOnce deployment?

查看:201
本文介绍了我在哪里可以安全地存储ClickOnce部署的数据文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用 ApplicationDeployment.CurrentDeployment.DataDirectory 来存储客户端在运行时下载的内容,预计每次应用启动时都会存在该内容,但是现在我

I have been using ApplicationDeployment.CurrentDeployment.DataDirectory to store content downloaded by the client at runtime which is expected to be there every time the app launches, however now I've found this changes seemingly randomly if the application is updated.

在单击一次部署中为应用程序存储用户数据的最佳可靠方法是什么?

What is the best reliable method for storing user data for the application in click-once deployments?

当前我一直在使用以下方法

Currently I've been using the following method

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应用程序中的本地和远程数据,位于标题 ClickOnce数据目录

I originally followed the article Accessing Local and Remote Data in ClickOnce Applications under the heading ClickOnce Data Directory which states this is recommended path.

注意 CreateDirectory(string)创建目录(如果尚不存在的话)。

NOTE: CreateDirectory(string) simply creates a directory if it doesn't already exist.

我发现问题的根本原因是我正在创建许多文件和一个索引文件,即该索引文件包含绝对路径,单击一次即可在升级时移动内容(或副本),因此绝对路径不再存在。我将按照Damokles的建议研究隔离存储,以了解这是否对单击一次部署有相同的副作用。

I have found the root cause of my problem is I'm creating many files and an index file, this index file contains absolute paths, click-once moves the content (or copies) on an upgrade, so the absolute paths no longer exist. I will investigate isolated storage as Damokles suggests to see if this has the same side affect for click-once deployments.

推荐答案

另一种选择是在用户的AppData文件夹中为您的应用程序创建目录并将其存储在该目录中。您可以使用以下方法获得此路径:

Another option is to make a directory for your application in the user's AppData folder and store it there. You can get a path to that with this:

Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)

您会发现很多应用程序都使用它(它是本地等效的)。在ClickOnce版本之间也不会移动。

You'll find a lot of applications use that (and it's local equivalent). It also doesn't move around between ClickOnce versions.

这篇关于我在哪里可以安全地存储ClickOnce部署的数据文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆