C # double-click the custom file icon to start (modify the registry ),
User-Defined files generated by the program. For example, the suffix is. test.
How can I directly start and open the program and the file?
1. Double-click to open
2. custom files are displayed with icons
3. Right-click a custom file and select the corresponding attribute.
Background Code: (how to modify information in the Registry)
// Tool startup path string toolPath = System. windows. forms. application. startupPath + "\ mail tool .exe"; string extension = SptdConst. fileExtension; string fileType = "Email File"; string fileContent = "text/plain"; // obtain information Microsoft. win32.RegistryKey registryKey = Microsoft. win32.Registry. classesRoot. openSubKey (extension); if (registryKey! = Null & registryKey. OpenSubKey ("shell ")! = Null & registryKey. OpenSubKey ("shell"). OpenSubKey ("open ")! = Null & registryKey. OpenSubKey ("shell"). OpenSubKey ("open"). OpenSubKey ("command ")! = Null) {var varSub = registryKey. openSubKey ("shell "). openSubKey ("open "). openSubKey ("command"); var varValue = varSub. getValue (""); if (Object. equals (varValue, toolPath + "% 1") {return ;}// Delete Microsoft. win32.Registry. classesRoot. deleteSubKeyTree (extension, false); // registryKey = Microsoft. win32.Registry. classesRoot. createSubKey (extension); registryKey. setValue ("file type", fileType); registryKey. setValue ("Content Type", fileContent); // sets the default icon Microsoft. win32.RegistryKey iconKey = registryKey. createSubKey ("DefaultIcon"); iconKey. setValue ("", System. windows. forms. application. startupPath + "\ logo. ico "); // set the default program path to registryKey = registryKey. createSubKey ("shell \ open \ command"); registryKey. setValue ("", toolPath + "% 1"); // disable registryKey. close ();
After modifying the registry information, double-click the file to start the software. How can I operate it in the code?
// Double-click Start to open it. // if there is a space in the original path, multiple elements such as if (e. args. length> 0) {string filePath = String. join ("", e. args. toArray (); FileInfo file = new FileInfo (filePath); if (file. exists) {EmailToolConst. doubleClickSptdFilePath = file. fullName ;}}
Then, you can check whether DoubleClickSptdFilePath has a value in the loaded method of the main program. If yes, you can obtain the file in the path and continue the operation.