I have a WPF application written in C# 11 targeting .NET 7. It will be packaged as MSIX and published to the Microsoft Store. (Although, I am side-loading it for now.) I have added a File Type Association for .xyz
files to the package manifest.
I sideload the application on my Windows 11 machine successfully. Then, I double-click a .xyz
file. Windows opens my program, as expected.
However, I cannot retrieve the path to the file that caused the application to open.
I have tried the following:
- Override
Application.OnStartup(StartupEventArgs e)
and use e.Args.
Args
contains only one argument, and it is of the form: -ServerName:App.AppXkxw1e314qzr8fyhwy5fza7r57vbx9dph.mca
- Call
Environment.GetCommandLineArgs()
.
This returns two arguments. The first one is the path to the application's DLL (of the form C:\Program Files\WindowsApps\BLAHBLAHBLAH_1.0.1.0_x64__dijkdkmnhep\MYAPP\MYAPP.dll), and the second is the same as the only argument in StartupEventArgs.Args
. (See #1.)
- Create Program.cs and override
Program.Main(string[] args)
.
args
is empty.
- Call
Windows.ApplicationModel.AppInstance.GetActivatedEventArgs()
This returns null
.
- Access
AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData[0]
.
In .NET 7, AppDomainSetup
no longer has the ActivationArguments
property.
References
Handle Protocol Activation and Redirection in Packaged Apps
How do I identify the file that launched my application
Get the path of the file that launched my app
Get file that the user opened the application with
Get path+filename of file that was opened with my application
Thank you for any assistance or ideas you may have. I have run out of things to try and places to Google/Bing.