internal ApplicationAssociation(FileAssociationManager associationmanager, string extension, string classid, string description) { _associationManager = associationmanager; _extension = "." + extension.TrimStart('.'); _classid = classid; if (!string.IsNullOrEmpty(description)) { // Write the description to the registry. using (RegistryKey regkey = Registry.ClassesRoot.CreateSubKey(_classid)) { regkey.SetValue(null, description); } } }
private void btnUoDoFileAssociate_Click(object sender, EventArgs e) { try { using (FileAssociationManager mgr = new FileAssociationManager()) { mgr.UnregisterApplicationAssociation(); } this.ShowMessage("已撤销文件关联"); } catch (Exception ex) { this.ShowMessage(ex.Message); } }
private void btnDoFileAssociate_Click(object sender, EventArgs e) { try { using (FileAssociationManager mgr = new FileAssociationManager()) { foreach (object item in cListBoxFileExtension.CheckedItems) { using (ApplicationAssociation ext = mgr.RegisterFileAssociation(item.ToString())) { ext.DefaultIcon = new ApplicationIcon(Application.ExecutablePath); ext.ShellOpenCommand = Application.ExecutablePath; ext.Associated = true; } } } this.ShowMessage("已关联文件"); } catch (Exception ex) { this.ShowMessage(ex.Message); } }