WPF; click once; Double Click file to launch; VS 2008

后端 未结 2 1146
说谎
说谎 2021-01-14 02:36

My application is only for me and co-workers, so I don\'t care if it\'s Click-Once or copy-the-exe. I want to be able to click a file with given extension in windows explor

相关标签:
2条回答
  • 2021-01-14 02:41

    First of all you should add file assoc for ClickOnce-publish (Select Project->Properties->Publish-Options->File Associations)
    Then add Reference to "System.Deployment"
    Then you could extract path in App.cs in such a manner, depending on type of startup (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;
        }
    
    0 讨论(0)
  • 2021-01-14 02:53

    Have you checked Environment.GetCommandLineArgs()? That shows the arguments with which your application was started.

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

    0 讨论(0)
提交回复
热议问题