Project Description
Association Manager is a library which makes it a lot easier for .NET developers to associate file extensions with their application.
  • Support for Windows "old" file associations
  • Support for "Default Programs" introduced in Windows Vista & Windows 7
  • Support for previous associated program when removing association

To install from nuget.org:
Install-Package rfc1459.AssociationManager


Register the associations used by your application. This step can be performed multiple times and will only maintain the known application associations.:

using (FileAssociationManager mgr = new FileAssociationManager())
{
   using (ApplicationAssociation ext = mgr.RegisterFileAssociation("doc"))
   {
      ext.DefaultIcon = new ApplicationIcon(Application.ExecutablePath);
      ext.ShellOpenCommand = Application.ExecutablePath;
      ext.Associated = true;
   }
   using (ApplicationAssociation ext = mgr.RegisterFileAssociation("txt"))
   {
      ext.DefaultIcon = new ApplicationIcon(Application.ExecutablePath);
      ext.ShellOpenCommand = Application.ExecutablePath;
      ext.Associated = true;
   }
}


UnRegister the associations used by your application when uninstalling.

using (FileAssociationManager mgr = new FileAssociationManager())
{
   mgr.UnregisterApplicationAssociation();
}



To retrieve information regarding an association
using (FileAssociationManager mgr = new FileAssociationManager())
{
   using (ApplicationAssociation fileExt = mgr.GetFileAssociation(".txt"))
   {
      Console.WriteLine($"{fileExt.ShellOpenCommand}");

      IconManager iconMgr = new IconManager(fileExt.DefaultIcon);
      Icon icon = iconMgr.GetIcon(IconManager.IconSize.Small, "*.txt");
   }
}

Last edited Nov 29, 2016 at 6:22 PM by rfc1459, version 11