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 :(

tshepang
  • 12,111
  • 21
  • 91
  • 136
Bodo
  • 127
  • 1
  • 1
  • 3
  • "doesn't work" is not a good problem description. How exactly does it not work? – ChrisWue May 23 '11 at 07:21
  • It doesn't open file, or error: The UNC path should be of the form \\server\share – Bodo May 23 '11 at 07: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 '11 at 07: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 '11 at 07:27
  • When i use second method - nothing happens. No error, no loading file. Nothing. No, no from a network path. I used // to open file in application catalog. – Bodo May 23 '11 at 07:27
  • after opening the file you have to read the contents from the FileStream object. I'm not sure but it seems that you want to ShellExecute the file, if yes then this is completely irrelevant to fileStream objects; consider using `System.Diagnostics.Process` class. – fardjad May 23 '11 at 07:29
  • I was trying to do it according http://www.csharp-examples.net/filestream-open-file/ . So what is the simpliest way to open this help file? – Bodo May 23 '11 at 07:32
  • CHM content is compiled and formatted, it's not plain text and can't be read like this. take a look at this: http://www.codeproject.com/KB/cs/decompilingchm.aspx and this: http://xtractpro.com/articles/Help-File-Extractor.aspx – fardjad May 23 '11 at 07:34
  • 1
    @fardjad: Can you put your comments into an answer? – ChrisWue May 23 '11 at 07:39
  • @Bodo do you want to programmatically open the file or do you want to invoke the chm file in a separate HH window ? – abhilash May 23 '11 at 07:44

7 Answers7

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.

Igor Popov
  • 9,795
  • 7
  • 55
  • 68
abhilash
  • 5,605
  • 3
  • 36
  • 59
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

fardjad
  • 20,031
  • 6
  • 53
  • 68
1
 Help.ShowHelp(this, AppDomain.CurrentDomain.BaseDirectory+"\\test.chm", HelpNavigator.Topic, "Welcome.htm");

Welcome is id of the welcome age in chm file

Code_Worm
  • 4,069
  • 2
  • 30
  • 35
1

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

Raviraj
  • 71
  • 1
  • 3
  • Please read http://stackoverflow.com/help/how-to-answer and improve your answer. Try to explain why your code differ from the question. – Ricardo Pontual Oct 20 '16 at 15:05
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"

MBen
  • 3,956
  • 21
  • 25
0

Simple do this

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

  • 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. – Alexandru Dicu Jan 18 '19 at 14:17