constant
constant

Reputation: 57

How to add an item to explorer context menu for UWP application

I've converted my WPF application using Desktop App Converter to appx package. I need to have an item in explorer context menu. I.e. user right mouse clicks on file and sees my item "Do action with Application" in main menu. On item selection my application starts with command line arguments of selected file. I don't need "windows.fileTypeAssociation" and "open with Application" in submenu. I want my item on top level menu.

So, the steps I've done:

  1. With Desktop App Converter I've get appx package and PackageFiles folder.
  2. In Package folder I've changed AppxManifest.xml file:

    ...
    <Extensions>
    <desktop4:Extension Category="windows.fileExplorerContextMenus">
      <desktop4:FileExplorerContextMenus>  
        <desktop4:ItemType  Type=".jpg">
          <desktop4:Verb Id="Foo" Clsid="91dce9db-f066-366b-be01-abcdd41e5cf1"/>
        </desktop4:ItemType>
      </desktop4:FileExplorerContextMenus>
     </desktop4:Extension>
    </Extensions>
    ...
    
  3. Install application with commands: add-appxpackage -path \AppxManifest.xml -Register

Note: I haven't found where could I get ClsId for my application and this is GUID of the other application.

So after all these actions I've not seen any new items in context menu. I've tried to do "windows.fileTypeAssociation" before in similar way. It's worked for me.

Researhing the subj I've found that many colleagues tried to solve this problem with no success, for example:

https://github.com/MicrosoftDocs/winrt-related/issues/117

https://social.microsoft.com/Forums/azure/ru-RU/ef1af46e-a06d-4ba3-9ec8-48ce3ceb0abc/visual-studio-2017-windows-application-packaging-desktop4fileexplorercontextmenus-not-working?forum=wpdevelop&prof=required

https://social.msdn.microsoft.com/Forums/expression/en-US/d81ed0c7-a96a-4b47-a685-3f927fef9438/uwphow-to-add-an-item-into-windows-explorer-context-menu?forum=wpdevelop

Summary. Is it possible to implement explorer context menu item for UWP ? If possible, what I've doing wrong ? Have somebody done it with success ? Any working solutions, examples ? Sensible manuals ? And where could I get "Clsid" ?

Upvotes: 3

Views: 1654

Answers (1)

Nico Zhu
Nico Zhu

Reputation: 32775

The CLSID can be that of a packaged COM server declared in the same app’s manifest. Here’s an example:

 <desktop4:Extension Category="windows.fileExplorerContextMenus">
          <desktop4:FileExplorerContextMenus>
           <desktop4:ItemType Type=".txt">
              <desktop4:Verb Id="Command2" Clsid="E694BDCD-DCEB-42B6-9C1A-8A604F8XXXXX" />
            </desktop4:ItemType>
          </desktop4:FileExplorerContextMenus>
        </desktop4:Extension>
                <com:Extension Category="windows.comServer">
          <com:ComServer>
            <com:SurrogateServer  DisplayName="context menu verb handler 2">
              <com:Class Id="E694BDCD-DCEB-42B6-9C1A-8A604F89F2D1" Path="Providers.dll" ThreadingModel="STA"/>
            </com:SurrogateServer>
          </com:ComServer>
        </com:Extension>

Clsid is the comserver that should implement IExplorerCommand representing the context menu verb.

Upvotes: 1

Related Questions