我不確定這是否是問題的根源,但我強烈建議您更改存儲應用程序信息的結構。
當通過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