我的应用程序仅供我和同事使用,所以我不在乎它是 Click-Once 还是 copy-the-exe。我希望能够在 Windows 资源管理器中单击具有给定扩展名的文件,并让我的程序启动并打开该文件。我无法让它捕获文件名。
表面上的解决方案:
我正在尝试的代码如下,此时我要做的就是将单击的文件的名称放在文本框中。我怀疑我的相关无知是关于如何从 Windows 资源管理器中引用单击一次应用程序。当我构建时,我最终得到一个名为 setup.exe 的文件,一个名为 Wis.application 的文件,当我单击“setup”进行安装时,我最终得到一个类型为“Click-once application reference”的快捷方式。 C:\Users\ptom\AppData\Roaming\Microsoft\Windows\开始菜单\程序\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";
}
}
}
}
}
谢谢