The custom file generated by the program, such as the suffix is . Test
How does this file directly start the open program and open the file?
1. Double-click to open
2, the custom file, has the icon to display
3, the custom file, right click has the corresponding attribute
Background code: (How to modify information in the registry)
Tool startup path String toolpath = System.Windows.Forms.Application.StartupPath + \ Mail gadget. exe;
string extension = Sptdconst.fileextension;
String fileType = "Email File";
String filecontent = "Text/plain";
Get 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);
File Registration RegistryKey = Microsoft.Win32.Registry.ClassesRoot.CreateSubKey (extension);
RegistryKey.SetValue ("File type", FileType); RegistryKey.SetValue ("Content Type", filecontent);
Set default icon Microsoft.Win32.RegistryKey Iconkey = Registrykey.createsubkey ("DefaultIcon");
Iconkey.setvalue ("", System.Windows.Forms.Application.StartupPath + "\\logo.ico");
Set the default open program path RegistryKey = Registrykey.createsubkey ("Shell\\open\\command");
RegistryKey.SetValue ("", Toolpath + "%1"); Close Registrykey.close ();
After modifying the registry information, double-click the file to start the software, then how to operate in the code?
Double-click Start
on//If there are spaces in the existing path, it will be decomposed into multiple elements
if (e.args.length > 0)
{
string filePath = String.Join ("", E. Args.toarray ());
FileInfo file = new FileInfo (filePath);
if (file. Exists)
{
Emailtoolconst.doubleclicksptdfilepath = file. FullName
}
}
You can then determine if there is a value in the main program method, and if so, loaded DoubleClickSptdFilePath get the file under the path to continue.
The above is a small series for everyone to organize the C # set up a custom file icon to achieve the start of the whole content, I hope this article content for everyone's study or work can have some help, if there is doubt can message exchange.