I want my application to be able to access an external help file. I also want the user to be able to install the program is his chosen folder. The problem this creates is that I don't know how to specify the Namespace for the help provider. I want to have the help file installed in the "Help" folder under Windows. I've been trying to figure this out, and can't. Can someone help me out here? Here's the code I was trying to use for the click event:

// get environment variable representing the Windows folder
String s = Environment.GetEnvironmentVariable("windir");
// set h to WindowsPath\Help\helpfile
String h = s + "/Help/MyHelpFile.chm";
Help.ShowHelp(this, HelpProvider1.HelpNamespace);

When I run this, I get no build errors, but when I click the Help menu item, it throws an exception indicating the URL isn't correct. I have tried several ways to make the Namespace property be the path to the .chm file with no success.

String h = s + "/Help/MyHelpFile.chm";

shouldn't that be:

String h = s + @"\Help\MyHelpFile.chm";

?

I tried that, but I must still be doing something wrong. Seems to me the key is in the line:

Help.ShowHelp(this, HelpProvider1.HelpNamespace);

...but I can't find anything in my quite limited understanding to make it work. I know that the Namespace property points to the file and it's path, but I can't figure out how to give the namespace property anything other than an explicit filename.

try this

String s = Environment.GetEnvironmentVariable("windir");
			// set h to WindowsPath\Help\helpfile
			String h = s + "\\Help\\MyHelpFile.chm";
			
			Help.ShowHelp(this, h);

your second parameter for ShowHelp is wrong (it has to be the path to your help file)

try this:

/ get environment variable representing the Windows folder
String s = Environment.GetEnvironmentVariable("windir");
// set h to WindowsPath\Help\helpfile
String h = s + @"\Help\MyHelpFile.chm";
Help.ShowHelp(this, h);

Thanks, gentlemen!
You know what? I feel pretty silly for not trying that. I actually thought about it, but I kept telling myself I couldn't directly use a variable for that parameter, even though it made sense.
I guess I am developing some programming instinct but just haven't learned to trust it yet.

This article has been dead for over six months. Start a new discussion instead.