How to open a CHM file through your C# application.

This simple tutorial will guide you, how to use a CHM help file with your Microsoft Visual C# projects or even small applications. To use a CHM help manual for your application, you need to first create a CHM help file for your project. After Creating your CHM file, you need to link it thorough your C# application. Let me show you how you can open it from your C# application.

tutorial sample window

Assuming that you all know how to start a new project on visual studio, I skip all those steps. As you can see above there is simple windows application contains only a single button. Now to open a CHM file by clicking on the “View Help Topics” Button, you have to write a single line code only. Double click on the “View Help Topics” Button and write the code below inside the scope of Button1_Click function.

System.Diagnostics.Process.Start (Application.StartupPath + "\\Help Document.chm");

After writing this code it will look like this

private void button1_Click(object sender, RoutedEventArgs e)

{

System.Diagnostics.Process.Start(Application.StartupPath + \\Help Document.chm);

}

Make sure your CHM file is in your application folder. Now Debug your application and test it. You can also open any other file or application using the code above through your C# application. Hope you find it helpful. Please feel free to ask anything and do comment.

17 comments:

  1. Thanks for the help... :)

    Rajeev

    ReplyDelete
  2. thanks from Colombia =)

    ReplyDelete
  3. What does the StartupPath refer to? When I copy pasted the above code into my application, the StartupPath has error.

    ReplyDelete
  4. AnonymousMay 08, 2010

    The same directory that the exe is running from.

    ReplyDelete
  5. A bit improved (in order to avoid an unhandled exception if the help file does not exist) + you should use Path.Combine():

    string helpFileName = System.IO.Path.Combine(Application.StartupPath, "Xxxx.chm");

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

    ReplyDelete
  6. so cool !!

    ReplyDelete
  7. Nice dude... It's works @hfrmobile.

    ReplyDelete
  8. Hey guys sorry was stuck in other activities so cant reply to you people. Well I am glad it is helpful for you guys. I am looking forward to post on stuff related to VS 2010 and other upcoming technologies. Once again I appreciate all of you to take interest in the post.

    ReplyDelete
  9. Thank you very much...

    ReplyDelete
  10. Thank you!

    ReplyDelete
  11. AnonymousJuly 20, 2012

    Thanks it really works

    ReplyDelete
  12. Grazie, effective and to the point.

    ReplyDelete
  13. Thanks a lot! We used this in our school project :)

    ReplyDelete
  14. How do you open the chm file to a particular topic ID?

    ReplyDelete
  15. [C#] public static void ShowHelp(Control, string);

    System.Windows.Forms.Help.ShowHelp(this, Application.StartupPath + "\\XXXXX.chm");

    ReplyDelete