2

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

Tan
  • 778
  • 3
  • 18
  • 36
  • Is this the path it uses, while you are debugging inside Visual Studio or while the application is installed / deployed? – Marco Apr 15 '16 at 06:08
  • Possible duplicate of [How can I get the application's path in a .NET console application?](http://stackoverflow.com/questions/837488/how-can-i-get-the-applications-path-in-a-net-console-application) – Thomas Weller Apr 15 '16 at 06:09
  • Possible dublicate Relative [Paths in Winforms](http://stackoverflow.com/questions/1019641/relative-paths-in-winforms) – Alexej Sommer Apr 15 '16 at 06:10
  • when i am running from visual studio its getting applicationfolder/bin/release/something.chm my something.chm file is under applicationfolder/something.chm. even when i deploy based on installed location i want the something.chm file path to be fetched – Tan Apr 15 '16 at 06:16
  • common mate why would i post question if it is duplicate. i will check the answers of previous similar questions and check if it was possible solution and if it is not then only i will post. – Tan Apr 15 '16 at 07:08
  • One thought, the reportmanager.hhp (project file of HTMLHelp Workshop or whatever application you are using) resides in your C# Project - this is not recommended. Please hold application development and help authoring in different places. – help-info.de Apr 15 '16 at 13:51

3 Answers3

2

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

help-info.de
  • 6,695
  • 16
  • 39
  • 41
  • its working with debug and release modes, after following your instructions. but when i add the setup project and deploy the application. and run the application from setup file, its not working. can you please help – Tan Apr 15 '16 at 18:25
  • do i need to add the chm files to application folder of setup project – Tan Apr 15 '16 at 18:27
  • thanks mate, it was very helpful and solved my problem – Tan Apr 15 '16 at 18:46
1

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);
Zein Makki
  • 29,485
  • 6
  • 52
  • 63
  • still going to bin/release folder – Tan Apr 15 '16 at 06:14
  • When you deploy the application, the results will be different. This returns the actual directory of the EXE you're running. – Zein Makki Apr 15 '16 at 06:16
  • oh then its gonna be fine. ill deploy and test. thanks why windows development is like hell when compared to web – Tan Apr 15 '16 at 06:17
  • You can check the edited answer also, it is more guaranteed to get you the correct result. – Zein Makki Apr 15 '16 at 06:19
  • its not working i have deployed my application and installed and checked its not showing. please help – Tan Apr 15 '16 at 07:01
  • Display the location "HelpFilepath" in a MessageBox, check if the chm is deployed with your application (Use File.Exists). Maybe the location of your chm is changing after deployment. Check Directory.GetFiles(exeDirectory) results and display them in some way on the screen. – Zein Makki Apr 15 '16 at 07:13
0

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");
Community
  • 1
  • 1
Alexej Sommer
  • 2,677
  • 1
  • 14
  • 25