// Unregister the Jump List file handle private void btnUnregisterFileType_Click(object sender, EventArgs e) { // Check whether the application ID has been registered if (!HelperMethod.IsApplicationRegistered(TaskbarManager.Instance.ApplicationId)) { MessageBox.Show(".txt file type has not been registered yet!"); return; } // Check whether the application is runas Admin, since we need the Admin privilege // to modify the HKCR registry values if (!HelperMethod.IsAdmin()) { // Ask the user whether to elevate the application var result = MessageBox.Show("This operation needs Admin privilege!" + "\r\nRestart and run the application as Admin?", "Warning!", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { try { // Call helper method to restart the application as Admin HelperMethod.RestartApplicationAsAdmin(); } catch { return; } Application.Exit(); // Kill the current application instance } else { return; } } // If the application is runas Admin try { // Call helper method to unregister the .txt file handle HelperMethod.UnregisterFileAssociations(TaskbarManager.Instance.ApplicationId, false, TaskbarManager.Instance.ApplicationId, Assembly.GetExecutingAssembly().Location, ".txt"); MessageBox.Show(".txt file type is unregistered successfully!"); } catch (Exception ex) { MessageBox.Show("Error unregistering file type association:\r\n" + ex.Message); } }
// Add a custom shell item to the custom category private void btnAddItem_Click(object sender, EventArgs e) { try { // Check the if the file name is valid if (!HelperMethod.CheckFileName(tbItem.Text)) { return; } // Create a .txt file in the temp foler and create a shell item for this file JumpListItem jli = new JumpListItem(HelperMethod.GetTempFileName(tbItem.Text)); // Add the shell item to the custom category _currentCategory.AddJumpListItems(jli); JumpList.Refresh(); // Refresh the Jump List } catch (Exception ex) { MessageBox.Show(ex.Message); } }