在C#中打开CHM(帮助文件)

我正在尝试在C#中打开帮助文件(chm扩展名)。

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

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

不起作用:(

您可以使用 –

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

所以假设你在Form / Control中

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

ShowHelp方法还提供重载以转到位于已编译的HTML帮助文件内的特定主题和帮助页面。

在MSDN上读取System.Windows.Forms.Help.ShowHelp

反编译CHM文件

就像在命令提示符下执行以下命令一样简单。

 hh.exe -decompile   

例如:

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

执行上述命令后,您应该在C:\foo\helpchmextracted文件夹中找到反编译的内容。

根据请求将我的评论添加到答案中:

似乎第一个语句中的文件名不正确,但第二个语句中的文件名应该有效,除非文件被锁定,不存在或者您没有访问该文件的权限。 如果你想要ShellExecute文件,那么你应该使用System.Diagnostics.Process类,但是如果你想提取CHM的内容,因为它是编译和格式化的,所以它不能像纯文本文件那样被读取。 看看这些链接:

使用C#反编译CHM(帮助)文件

CHM帮助文件提取器

  string helpFileName = @"c:\help.chm"; if (System.IO.File.Exists(helpFileName)) { Help.ShowHelp(this, helpFileName ); } 

如果这不是工作尝试

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

那么第二行应该没问题,如果文件不存在则应抛出exception。 需要更具体地说明你的意思“它不起作用”

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

欢迎是chm文件中欢迎时代的ID

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

这很简单

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