Use C # To convert HTML files to CHM files)

Source: Internet
Author: User

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

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.