我不确定这是否是问题的根源,但我强烈建议您更改存储应用程序信息的结构。
当通过ClickOnce安装应用程序时,该应用程序安装在用户的文件夹中,并且其相当模糊。此外,位置可能会随着后续应用程序更新而改变,所以您不能保证任何缓存的,下载的文件都将从更新更新到更新。
为解决此问题,ClickOnce确实提供了一个Data
目录,该目录未被模糊处理,可用于缓存本地数据。唯一需要注意的是,此目录不适用于应用程序的非ClickOnce实例(例如在VS调试器中运行的版本)。
要解决此问题,您应该编写一个可用于获取您的数据目录,无论您的分发或执行方式如何。以下代码是该函数的外观示例:
//This reference is necessary if you want to discover information regarding
// the current instance of a deployed application.
using System.Deployment.Application;
//Method to obtain your applications data directory
public static string GetAppDataDirectory()
{
//The static, IsNetworkDeployed property let's you know if
// an application has been deployed via ClickOnce.
if (ApplicationDeployment.IsNetworkDeployed)
//In case of a ClickOnce install, return the deployed apps data directory
// (This is located within the User's folder, but differs between
// versions of Windows.)
return ApplicationDeployment.CurrentDeployment.DataDirectory;
//Otherwise, return another location. (Application.StartupPath works well with debugging.)
else return Application.StartupPath;
}
来源
2012-01-26 17:50:02
RLH
为什么'StartupPath'?可能对Vista/W7/W8没有权限。 ['Environment.GetFolderPath()'](http://msdn.microsoft.com/en-us/library/14tx8hby.aspx)可以帮助找到更好的。 – user7116
谢谢,如果我允许用户浏览磁盘上的文件夹,说大量的图像,我的应用程序就可以访问c:\ myimages所有的时间? –
@BrianHvarregaard:只要他们每次运行它都有权访问该文件夹。 – user7116