private void btnAssociate_Click(object sender, EventArgs e) { bool associated = new FileAssociation { Extension = ".abc", ProgId = "MyWordSelectionProgramUpdate", FileTypeDescription = "My Word Selection Program Update" }.SetAssociation(); }
public static bool SetAssociation(this FileAssociation fileAssociation) { bool madeChanges = false; madeChanges |= SetKeyDefaultValue(@"Software\Classes\" + fileAssociation.Extension, fileAssociation.ProgId); madeChanges |= SetKeyDefaultValue(@"Software\Classes\" + fileAssociation.ProgId, fileAssociation.FileTypeDescription); madeChanges |= SetKeyDefaultValue($@"Software\Classes\{fileAssociation.ProgId}\shell\open\command", "\"" + fileAssociation.ExecutableFilePath + "\" \"%1\""); madeChanges |= SetKeyDefaultValue(@"Software\Classes\" + fileAssociation.ProgId + @"\DefaultIcon", fileAssociation.IconPath); return(madeChanges); }