我的應用程序僅適用於我和同事,所以我不在乎它是Click-Once還是Copy-the-exe。我希望能夠在Windows資源管理器中單擊具有給定擴展名的文件,並啓動我的程序並打開該文件。我無法獲取它來捕獲文件名。WPF;點擊一次;雙擊文件啓動; VS 2008
表面上的解決方案:
我想要的代碼如下,並在這一點上所有我想要做的就是把點擊文件名的文本框中。我懷疑我的相關無知是關於如何從Windows資源管理器引用一次性應用程序。當我建立時,我最終得到一個名爲setup.exe的文件,一個名爲Wis.application的文件,當我點擊「setup」安裝它時,我最終得到了一個「Click-once application reference」類型的快捷方式,在「 C:\ Users \ ptom \ AppData \ Roaming \ Microsoft \ Windows \ Start Menu \ Programs \ Wis「。我試着將文件與通過安裝創建的快捷方式相關聯,並將文件與setup.exe關聯。當我點擊該文件時,應用程序將啓動,但表示 AppDomain.CurrentDomain.SetupInformation.ActivationArguments爲空。 (通過「指示」我的意思是文本框被填充來自我測試的文本以查看它是否爲空)。如果我從調試中運行應用程序,或者只是通過從開始菜單運行應用程序,它會按照我所期望的那樣進行,遵循指示ActivationArguments不爲空的代碼路徑,但其ActivationData(string [])的長度0
下面是從app.xaml.cs代碼
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Windows;
namespace Wis
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
// Check if this was launched by double-clicking a doc. If so, use that as the
// startup file name.
if (AppDomain.CurrentDomain.SetupInformation.ActivationArguments == null)
{
this.Properties["DoubleClickedFileToLoad"] = "There were no activation arguments AGAIN";
}
else
{
if (AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData != null
&& AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData.Length > 0)
{
this.Properties["DoubleClickedFileToLoad"] =
AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData[0];
}
else
{
this.Properties["DoubleClickedFileToLoad"] = "Type in a file name";
}
}
}
}
}
感謝
我粘貼了你的代碼;你有一個名爲ApplicationDeployment的對象;我一開始就把它切掉了,它工作。我必須添加一個對System.Deployment的引用來使用第一個測試。 – 2010-11-20 20:37:02