2012-01-25 136 views
0

我正在構建數字標牌應用程序,我想用ClickOnce部署它。 (我覺得這是最好的方法。)當我從Visual Studio(VS)啓動應用程序時,它效果很好。應用程序會下載大量的圖片,從我的web服務,並將它們保存到磁盤:當我需要生成幾個大文件時使用ClickOnce?

string saveDir = new FileInfo(Assembly.GetExecutingAssembly().Location).Directory.FullName; 

當我開始我的部署的應用程序,它顯示啓動畫面,然後消失。該進程保持運行,但UI不顯示。我想知道如果我的saveDir如上所示是給我麻煩?

如何找到我安裝的應用程序? (我需要製作許可證文件等)

回答

3

我不確定這是否是問題的根源,但我強烈建議您更改存儲應用程序信息的結構。

當通過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; 
} 
+0

爲什麼'StartupPath'?可能對Vista/W7/W8沒有權限。 ['Environment.GetFolderPath()'](http://msdn.microsoft.com/en-us/library/14tx8hby.aspx)可以幫助找到更好的。 – user7116

+0

謝謝,如果我允許用​​戶瀏覽磁盤上的文件夾,說大量的圖像,我的應用程序就可以訪問c:\ myimages所有的時間? –

+0

@BrianHvarregaard:只要他們每次運行它都有權訪問該文件夾。 – user7116

相關問題