How to associate Maui app with specific file extension without writing the registry

345 views Asked by At

I saw that there is a solution by writing values to registry, is there more human way to this? I found that can be done easily for ClickOnce apps

https://learn.microsoft.com/uk-ua/visualstudio/deployment/how-to-create-file-associations-for-a-clickonce-application?view=vs-2019

in the example the specific tag is added to application manifest.

Can I do the same for MAUI?

Probably yes, I found the guy who did it, but there no details at all

File activation in MAUI

1

There are 1 answers

1
Liqun Shen-MSFT On

You could add the following code to manifest in Platform/Windows folder. Suppose the specific file extension is .fff

<Extensions>
 <uap:Extension Category="windows.fileTypeAssociation">
  <uap:FileTypeAssociation Name="fff">
      <uap:SupportedFileTypes>
          <uap:FileType>.fff</uap:FileType>
      </uap:SupportedFileTypes>
      <uap:DisplayName>FFFLaunch</uap:DisplayName>
  </uap:FileTypeAssociation>
 </uap:Extension>   
</Extensions>

And override MauiWinUIApplication.OnLaunched like File activation in MAUI

protected override void OnLaunched(LaunchActivatedEventArgs args)
{
    base.OnLaunched(args);

    AppActivationArguments appActivationArguments = Microsoft.Windows.AppLifecycle.AppInstance.GetCurrent().GetActivatedEventArgs();

    if (appActivationArguments != null)
    {
        if (appActivationArguments.Kind is ExtendedActivationKind.File)
        {
            ...
           
        }
    }
}

Hope it helps.