Some HTML files need to be converted to CHM files due to work needs these days.ProgramCombined.
Later I found ndoc, which contains a sectionCodeIt is related, so I began to analyze the code. After writing the code, I would like to summarize: the main thing is to use a soft hhc.exe to compile HTML files. The program needs to write specific data into the HHP and HHC files.
The main code is as follows:
Copy C # code save code public void compileproject ()
{
Process helpcompileprocess = new process (); // create a new process. ndoc uses process to start HHC. EXE to compile a CHM File.
Try
{
/// Determine whether a file exists and is not occupied
Try
{
String Path = _ chmfile; // CHM generation path
If (file. exists (PATH)
{< br> file. delete (PATH);
}< BR >}< br> catch
{< br> throw new exception ("file opened! ");
}
Processstartinfo = new processstartinfo ();
Processstartinfo. windowstyle = processwindowstyle. hidden;
Processstartinfo. filename = hhcfile; // call the HHC. EXE file.
Processstartinfo. Arguments = "\" "+ path. getfullpath (getpathtoprojectfile () +" \ ""; // obtain an empty HHP File
Helpcompileprocess. startinfo = processstartinfo;
// Start generating ....
Helpcompileprocess. Start ();
Helpcompileprocess. waitforexit (); // The component waits for the associated process to exit indefinitely.
If (helpcompileprocess. exitcode = 0)
{
MessageBox. Show (new exception (). Message );
}
}
Finally
{
Helpcompileprocess. Close ();
}
}
Public void openprojectfile ()
{
Filestream FS = new filestream (getpathtoprojectfile (), filemode. Create );
Streamhtmlhelp = new system. Io. streamwriter (FS, system. Text. encoding. getencoding ("gb18030 "));
Streamhtmlhelp. writeline ("[files]");
}
Public void addfiletoproject (string filename)
{
Streamhtmlhelp. writeline (filename );
}
Public void closeprojectfile (String title)
{
Streamhtmlhelp. writeline ();
Streamhtmlhelp. writeline ("[Options]");
Streamhtmlhelp. writeline ("Title =" + title );
Streamhtmlhelp. writeline ("compatibility = 1.1 or later ");
Streamhtmlhelp. writeline ("compiled file =" + getcompiledhtmlfilename (); // CHM File Name
Streamhtmlhelp. writeline ("Contents file =" + getcontentshtmlfilename (); // HHC file name
Streamhtmlhelp. writeline ("Default topic =" + _ defaulttopic); // response page
Streamhtmlhelp. writeline ("display compile progress = No"); // whether to display the compilation process
Streamhtmlhelp. writeline ("Language = 0x804 Chinese (China)"); // CHM File Language
Streamhtmlhelp. writeline ();
Streamhtmlhelp. writeline ("[infotypes]");
Streamhtmlhelp. Close ();
}
From: http://www.cnblogs.com/monthkey/archive/2004/06/15/15995.aspx