Display CHM in Web pages (C # csharp. NET ASP. WinForm)

Source: Internet
Author: User

A CHM is a "compiled Help file" compiled primarily by the. HHC (catalog file),. HHK (index file), and the corresponding Help topic file (. html,.htm).

Method comparison

There are several ways to display CHM content in a Web page:

    1. Use some tools to decompile, restore the CHM file to the above related files, and list the directory through the HHC file, the content link to the corresponding HTML file
    2. Still is to decompile these files, the related directory and HTML file content directly into the database
    3. Parse CHM files directly

These methods have advantages and disadvantages:

    1. The advantage of Method 1 is convenient and quick, the disadvantage is obvious, the scattered HTML is not easy to manage and is not conducive to search
    2. The advantage of Method 2 is that the database is directly present, the query is convenient, the structure and content should be inserted into the database by traversing the directory, and the location of the picture resource file can be re-organized, which is a little tedious.
    3. The advantage of Method 3 is that it is not necessary to decompile, the direct use is most convenient, the disadvantage is that parsing chm is too difficult

Personally, it is a relatively good way to deposit the database directly, but this is not the purpose of this article, this article uses the method of parsing CHM file directly.

Using the Open Source class library

This article mainly uses an open source class library on CodeProject: Http://www.codeproject.com/KB/cs/htmlhelp.aspx, and a little transformation for the web.

This HTMLHelp class library includes all the features of almost hh.exe (that is, the CHM Viewer for Windows desktop), which can be said to be very powerful.

but it has a problem, for the non-standard CHM file, the search function support is not very good, guessing may also be encoded has a relationship .

I tried a lot of tools to generate the CHM file, but not very good use of its search function, fortunately, it parses the CHM file, but also all the subject files (. htm,.html) are read out, so you can use these content and title to transform the search function, To fit my non-standard CHM file.

The main code of search function transformation is as follows:

public bool Searchtopics (string key, TreeView TreeView) {return Searchtopics (Key, TreeView, True);}    public bool Searchtopics (string key, TreeView treeview, BOOL filterhtml) {ArrayList result = new ArrayList ();    Searchtopic (key, result, ChmHelp.TableOfContents.TOC, filterhtml); BOOL HasData = result.    Count > 0; if (HasData) {treeview.        Nodes.clear (); foreach (Tocitem item in result) {TreeNode node = new TreeNode (item.            Name); Node. NAVIGATEURL = URLPrefix + item.            Local; Treeview.        Nodes.Add (node); }} return hasData;} static regex rehtmlfilter = new Regex ("<[^>]*>", regexoptions.compiled);p rivate void Searchtopic (String topic, ArrayList result, ArrayList Searchin, bool filterhtml) {foreach (Tocitem CurItem in Searchin) {if (curitem.c Hildren.            Count = = 0) {String temp = curitem.filecontents; if (filterhtml &&!string.    IsNullOrEmpty (temp)) {            temp = Rehtmlfilter.replace (temp, String.            Empty); } if ((!string.                IsNullOrEmpty (curitem.name) && curItem.Name.Contains (topic)) | | (!string. IsNullOrEmpty (temp) && temp. Contains (topic)) {result.            ADD (CurItem);        }} else {searchtopic (topic, result, Curitem.children, filterhtml); }    }}

For getting a single theme, HTMLHelp only provides search by title, but considering that the title may not be unique, this article also adds a search by URL.

Create a separate page, receive the URL to get the corresponding topic, and display it, it is also important to note that the URL may have some special characters such as "#", "%20" and other symbols, resulting in parameters not correctly passed the problem.

Preview:

The code is not a lot of paste, complete example: Click to download

Display CHM in Web pages (C # csharp. NET ASP. WinForm)

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.