将文件类型与.net安装程序相关联时,您将使用什么作为参数? [英] When associating a file type with .net installer, what do you use as the argument?

查看:70
本文介绍了将文件类型与.net安装程序相关联时,您将使用什么作为参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

与安装程序有关的newb性质可能再次显示出来,但是我发现安装程序中文件类型的msdn演练非常缺乏.我在其中找不到任何内容可以解释如何获取您刚刚单击的文件作为您的代码可以识别的值.我曾希望给定动词/动作的arguments属性的默认值可以满足我的需求.文件类型以& open开头是唯一的操作(对我来说很好).该动作/动词的参数参数设置为%1".那对我来说似乎没什么用,但是我希望它能以某种方式满足我的需求.

我的WPF应用程序初始化时有代码,其获取命令参数的方式如下:

Again my newb nature with installers is probably showing, but I am finding that the msdn walkthroughs for file types on their installers is terribly lacking. I can''t find anything in there that explains how to get the file you just clicked on as a value that your code can then recognize. I had hoped that the default value on the arguments property of a given verb/action would do what I need. The file type starts with &open as the only action (which is fine by me). That action/verb has an arguments parameter that is set to "%1". That didn''t look all that useful to me, but I had hoped that it would somehow be what I need.

I have code at the initialization of my WPF application that gets the command arguments as follows:

var args = Environment.GetCommandLineArgs();
            String fileName = "";
            if (args != null && args.Length > 0)
                fileName = args[0];
			InitializeComponent();
            _application = new ApplicationViewModel(fileName);



当我将字符串传递到该视图模型中时,它知道打开文件.如果失败,则会显示提示,提示无法打开哪个文件.毫不奇怪,提示说它无法打开空白或空字符串.

有人可以帮我指出我需要作为文件类型操作的参数来使我的代码知道我刚刚单击的文件的路径是什么吗?



When I pass a string into that viewmodel, it knows to open the file. If it fails it displays a prompt saying what file it failed to open. No surprise, the prompt is saying it couldn''t open a blank or empty string.

Can anyone please help point me to what I need to put as the argument for my file type action to let my code know what the path of the file I just clicked on is?

推荐答案

安装程序提供的默认参数值正确,但是上面的代码不是获取该参数的正确代码.

对于我的WPF应用程序,我必须进入app.xaml后面的代码.覆盖OnStartUp,并且参数位于args属性中.

The default parameter value provided by the installer is right, but the code above was not the right code to get to the parameter.

For my WPF app, I had to go into the code behind for app.xaml. Override the OnStartUp and you have the parameter in an args property.

public String LoadedFileName = "";
       protected override void OnStartup(StartupEventArgs e)
       {
           if (e.Args != null && e.Args.Length == 1)
           {
               String fileName = e.Args[0];
               if (!String.IsNullOrEmpty(fileName))
                   LoadedFileName = fileName;
           }
       }



然后在主窗口的代码中将Application.Current强制转换为适当的类,以便您可以查看LoadedFileName



Then in the code for main window you cast Application.Current as the appropriate class so you can look at the LoadedFileName


这篇关于将文件类型与.net安装程序相关联时,您将使用什么作为参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆