简体   繁体   中英

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.

在此处输入图片说明

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);

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 eg 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.

在此处输入图片说明

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");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM