C # double-click the custom file icon to start (modify the registry ),

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.