11

I'm trying to open help file (chm extension) in C#.

File.Open(@"//help.chm",FileMode.Open, FileAccess.Read, FileShare.Read);

and

FileStream fileStream = new FileStream(@"c:\help.chm", FileMode.Open);

doesn't work :(

10
  • "doesn't work" is not a good problem description. How exactly does it not work?
    – ChrisWue
    May 23, 2011 at 7:21
  • It doesn't open file, or error: The UNC path should be of the form \\server\share
    – Bodo
    May 23, 2011 at 7:23
  • It seems that the file name in the first statement is not correct however the second one should work unless the file is locked, not exists or you don't have permissions to access the file.
    – fardjad
    May 23, 2011 at 7:25
  • @Bodo do you want to open the file from a network path? Then it should be @"\\ServerName\Path\FileName" and you have to be authorized and have permissions.
    – fardjad
    May 23, 2011 at 7:27
  • 1
    @fardjad: Can you put your comments into an answer?
    – ChrisWue
    May 23, 2011 at 7:39

7 Answers 7

27

You can use -

System.Windows.Forms.Help.ShowHelp(Control, String)

So assuming you are in a Form/Control

Help.ShowHelp(this, "file://c:\\helpfiles\\help.chm");

ShowHelp method also provides overloads to go to specific topic and help page located inside the compiled HTML help file.

Read System.Windows.Forms.Help.ShowHelp on MSDN

Decompiling a CHM file

Is as easy as executing below command in the command prompt.

hh.exe -decompile <target-folder-for-decompiled-content> <source-chm-file>

For Example:

hh.exe -decompile C:\foo\helpchmextracted help.chm

After executing the above command you should find the decompiled content in the C:\foo\helpchmextracted folder.

1
  • How to display the help in same win form ?
    – VJOY
    Aug 6, 2012 at 15:34
6
        string helpFileName = @"c:\help.chm";
        if (System.IO.File.Exists(helpFileName))
        {
            Help.ShowHelp(this, helpFileName );                
        }

if this is not work try

        if (System.IO.File.Exists(helpFileName))
        {
            System.Diagnostics.Process.Start(helpFileName);              
        }
2

Adding my comments to an answer as per request:

It seems that the file name in the first statement is not correct however the second one should work unless the file is locked, not exists or you don't have permissions to access the file. If you want to ShellExecute the file then you should use System.Diagnostics.Process class, but if you want to extract the contents of the CHM, since is compiled and formatted, it can't be read like plain text files. Take a look at these links:

Decompiling CHM (help) files with C#

CHM Help File Extractor

1

Well the second line should be ok, if the file is not existent it should throw an exception. Need to be more specific about what you mean by " it doesn't work"

1
 Help.ShowHelp(this, AppDomain.CurrentDomain.BaseDirectory+"\\test.chm", HelpNavigator.Topic, "Welcome.htm");

Welcome is id of the welcome age in chm file

1

System.Diagnostics.Process.Start(@"c:\help.chm");

1
0

Simple do this

Help.ShowHelp(ParentForm, "chmFile.chm", "link.htm");

1
  • One comment here. By using this method, it is nice that you can open the help to a specific topic. However, this method will lock the chm file until you close your executable file. It doesn't matter if you close the chm file, the file will be locked forever. If you need to update the chm file, then better use Process.Start method. You will not have the ability to open a specific topic anymore, but at least, you can update the file if needed. In my case I had to update the help file by downloading a new version of it. If I had opened the help file before, I couldn't update it anymore. Jan 18, 2019 at 14:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.