确定应用程序是否由自定义文件C#启动

时间:2017-12-14 08:09:55

标签: c# wpf visual-studio file publish

我发布了WPF应用程序并添加了文件关联。 当我点击我的自定义文件*.bms时,我实际上想要阅读该文件并使用它。我怎样才能做到这一点?到目前为止,如果我点击*.bms文件,它只会打开应用程序。没有其他的。 我已经尝试过添加:

<Application x:Class="WpfApplication1.App"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         StartupUri="MainWindow.xaml"
         Startup="Application_Startup"> <!--this line added-->
<Application.Resources>

</Application.Resources>

private void Application_Startup(object sender, StartupEventArgs e)
{
    if(e.Args.Length == 1) //make sure an argument is passed
    {
        FileInfo file = new FileInfo(e.Args[0]);
        if(file.Exists) //make sure it's actually a file
        {
           //Do whatever
        }
    }
}

我从neeKo在This Question

的答案中得到了这个解决方案

但这对我来说也不适用。

0 个答案:

没有答案