Tan
Tan

Reputation: 788

How to display chm file in c# winforms application

I have added .chm file to my application root. when i fetch the file using below code it is referencing the path to bin/release/somehting.chm

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

i want to get the path relative to installation location of application. please help.

the chm file added to the root directory is not loading after deploying the application. its not even loading while debugging in visual studio and not giving any error.

enter image description here

Upvotes: 2

Views: 2244

Answers (3)

help-info.de
help-info.de

Reputation: 7260

As I can see the first code snippet from your question calling Help.ShowHelp isn't so bad. Sometimes I'm using the related code below. Many solutions are possible ... Please note, typos e.g. somehting.chm are disturbing in code snippets.

private const string sHTMLHelpFileName = "CHM-example.chm";
...

private void button1_Click(object sender, EventArgs e) {
  System.Windows.Forms.Help.ShowHelp(this, Application.StartupPath + @"\" + sHTMLHelpFileName);
  }

So, please open Visual Studio - Solution Explorer and check the properties of your CHM file. Go to the dropdown box shown in the snapshot below and set "Always copy" (here only German). Start your project in Debug mode and check your bin/debug output folder. Do the same for Release mode and output folder. The CHM should reside there and I hope your CHM call works.

enter image description here

Upvotes: 2

Alexej Sommer
Alexej Sommer

Reputation: 2679

Answer from similar topic is:

// get full path to your startup EXE
string exeFile = (new System.Uri(Assembly.GetEntryAssembly().CodeBase)).AbsolutePath;

// get directory of your EXE file
string exeDir = Path.GetDirectoryName(exeFile);

// and open Help
System.Windows.Forms.Help.ShowHelp(this, exeDir+"\\"+"somehting.chm");

Upvotes: 0

Zein Makki
Zein Makki

Reputation: 30022

You need :

String exeDirectory = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);

So :

String HelpFilepath = "file://" + Path.Combine(exeDirectory , "somehting.chm");
Help.ShowHelp(this, path);

Upvotes: 1

Related Questions