WPF click once; Double-click the file to run; VS 2008

My application is intended only for me and my colleagues, so I donโ€™t care if it is Click-Once or copy-the-exe. I want to be able to click on a file with a given extension in Windows Explorer and run my program and open this file. I can not get it to capture the file name.

Poison Solution:

http://blogs.msdn.com/b/avip/archive/2008/10/27/wpf-supporting-command-line-arguments-and-file-extensions.aspx

The code I'm trying to do below, and at this point all I am trying to do is put the name of the clicked file in the text box. I suspect that my corresponding ignorance is how to reference a one-time application from a Windows browser. When I create, I get a file called setup.exe, the Wis.application file, and when I click "setup" to install it, I get a shortcut like "Click-once application link" in "C: \ Users \ ptom \ AppData \ Roaming \ Microsoft \ Windows \ Start Menu \ Programs \ Wis ". I tried to link files with this shortcut created during installation and link files with setup.exe. When I click on the file, the application launches, but indicates that AppDomain.CurrentDomain.SetupInformation.ActivationArguments is null. (By "indicates" I mean that the text field is filled with the text from which I am testing to see if it is null). If I run the application from debugging or just run it from the start menu, it will do what I expect, following the code path that indicates that ActivationArguments is not null, but its ActivationData value (string []) is 0 in length.

Here is the code from 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"; } } } } } 

thanks

+4
source share
2 answers

First of all, you must add the associated file for ClickOnce-publish (Select Project-> Properties-> Publish-Options-> File Associations)
Then add a link to " System.Deployment "
Then you can extract the path in App.cs this way, depending on the type of launch (ClickOnce or Local)

  protected override void OnStartup(System.Windows.StartupEventArgs e) { var path = GetPath (e); } private static string GetPath(StartupEventArgs e) { if (!ApplicationDeployment.IsNetworkDeployed) return e.Args.Length != 0 ? e.Args[0] : null; if (AppDomain.CurrentDomain.SetupInformation.ActivationArguments == null) return null; var args = AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData; return args == null || args.Length == 0 ? null : new Uri(args[0]).LocalPath; } 
+3
source

Have you marked Environment.GetCommandLineArgs() ? This shows the arguments with which your application was launched.

If your application is associated with a file, it must contain the file name as one of the arguments.

+3
source

All Articles