Search code examples
c#windowswindows-explorerfile-association

Why are my contextmenu entries lower case?


I'm using BrendanGrant.Helpers.FileAssociation; (a NuGet package) to create file-associations for my application. It works fine so far. However, I have a problem with the ProgramVerbs:

When I create a ProgramAssociation and add verbs to it like this:

  var pai = new ProgramAssociationInfo(fai.ProgID);

  pai.Create(
    "App name",
    new[]
    {
      new ProgramVerb("Öffnen", Assembly.GetEntryAssembly().Location + " \"%1\""),
      new ProgramVerb("Bearbeiten", Assembly.GetEntryAssembly().Location + " \"%1\"")
    });
}

The Bearbeiten and Öffnen (edit and open) keywords are lowercase in the contextmenu of windows explorer:

enter image description here

I named the 2nd entry WAAAA to test if its something only changing the first character, but apparently its not.

What do I have to change, so that my Bearbeiten and Öffnen is uppercase in the context menu?


Solution

  • I checked this library and it seems that you have no influence on this behavior.

    This is the line that changes to lowercase:

    RegistryKey subKey2 = subKey1.CreateSubKey(verb.Name.ToLower());
    

    _

    protected void SetVerbs(ProgramVerb[] verbs)
    {
      if (!this.Exists)
        throw new Exception("Extension does not exist");
      RegistryKey registryKey = RegistryHelper.AssociationsRoot.OpenSubKey(this.progId, true);
      if (registryKey.OpenSubKey("shell", true) != null)
        registryKey.DeleteSubKeyTree("shell");
      RegistryKey subKey1 = registryKey.CreateSubKey("shell");
      foreach (ProgramVerb verb in verbs)
      {
        RegistryKey subKey2 = subKey1.CreateSubKey(verb.Name.ToLower());
        RegistryKey subKey3 = subKey2.CreateSubKey("command");
        subKey3.SetValue(string.Empty, (object) verb.Command, RegistryValueKind.ExpandString);
        subKey3.Close();
        subKey2.Close();
      }
      ShellNotification.NotifyOfChange();
    }
    

    Instead of collection assignment you should use AddVerb(ProgramVerb verb) method and then uppercase should be kept:

    pai.Create("App name", new ProgramVerb[0]);
    pai.AddVerb(new ProgramVerb("Öffnen", Assembly.GetEntryAssembly().Location + " \"%1\""));
    pai.AddVerb(new ProgramVerb("Bearbeiten", Assembly.GetEntryAssembly().Location + " \"%1\""));