-1

I am trying to make a program that only has a single exe file. That is a requirement.

But I also have to implement help for that program, so the user can know what does what. I decided to make a chm file and use a HelpProvider. Initially I thought I'd be able to embed the chm file and tell the HelpProvider to open it from the resources.resx.

Well, that didn't work.

Since I don't know of any other options to display help, without adding more files to the program or using online hosting or whatever, I decided I will be writing the embedded chm to the disk (when the user opens it) and deleting it after (this after I failed at coming up with a way to do so in memory).

The problem is creating the file with the FileOptions.DeleteOnClose flag and writing to it. If I

File.Create(path, 100, FileOptions.DeleteOnClose);
File.WriteAllBytes(path, mychm);

The file is locked by the Create method. If I put using on the Create method the file gets deleted before writing.

J. Doe
  • 1,147
  • 1
  • 13
  • 21
  • `File.Create` gives you a `FileStream`. Use that for writing only, and keep it around in a field so the stream in question won't get garbage collected. Dispose it explicitly when you're done with it. – Jeroen Mostert Nov 02 '17 at 16:12
  • 2
    It is not going to fly. A program (like hh.exe, the help viewer) needs to open this file with FileShare.Write and FileShare.Delete and it is not going to do that. Asking for help with such unrealistic requirements is not useful. – Hans Passant Nov 02 '17 at 16:16
  • Why would not you instead of creating and deleting help file create another project with help and merge it into your exe as describe here: https://stackoverflow.com/questions/10137937/merge-dll-into-exe. – Nick Nov 02 '17 at 16:25
  • @HansPassant, what's so unrealistic about it? You make it sound like I should only ask for help for simple matters. Yeah, that's really useful. – J. Doe Nov 02 '17 at 16:25
  • @Nick but how would I go about creating another project with help that doesn't have the same problems? Namely I don't understand what you mean by "project with help", I am trying to add help to this project. Please elaborate. – J. Doe Nov 02 '17 at 16:28
  • @J.Doe, add Class Library project to your Visual Studio solution. Put there c# class which contains help information you need. Use this class as you need. Then merge this project dll into exe as described in link in my previous message. This way you have one exe file. Or alternatively you can add class containing help information to your existing project, no need in merging in this case... – Nick Nov 02 '17 at 16:41
  • @Nick, the only way I know to add help information is by the use of the HelpProvider class and a chm file. I'm thinking you had something else in mind. I'd be glad to explore other options, I just didn't find any relevant ones. – J. Doe Nov 03 '17 at 07:50
  • @J.Doe I guess your help is mostly text. So create C# class with string fields and put your help here. In case of pictures consider making them embedded resources, you can do this with text also! See https://stackoverflow.com/questions/433171/how-to-embed-a-text-file-in-a-net-assembly – Nick Nov 03 '17 at 09:13

1 Answers1

1

Okay, so the code needs to be a single .exe. Fair enough.

Have you thought about having your application be the one that actually displays the help? I mean, I don't know what the requirements on the help actually are (Clickable Indexes? Table of contents? Tool Tips? etc) - but depending on how user-friendly you're required to make it, you could always simply add a Windows Form with a WebBrowser object and inject HTML contents directly into the WebBrowser (via myWebBrowserControl.Document).

I mean, this isn't optimal by any means. But it's an quick-and-dirty solution to the "Help-Enabled application with only a single .exe output" requirement.

EDIT: Additional idea. If you're writing this for internal use within a business, you can put the help file in an accessible location on the company network - and have your app link to the remote location. And on the flip side, if you're developing an app that users will download, you could develop online help and have the app link to your help's URL.

Kevin
  • 2,133
  • 1
  • 9
  • 21
  • That IS a good idea, I just thought it'd be a lot easier to do it with HelpProvider and chm. – J. Doe Nov 03 '17 at 07:52
  • You're probably right - CHM would make it a lot easier... but after the shenanigans you'd have to go through with 'one file only', I'm not sure it's worth it. Also, check out the ideas on my edit - if either of them are feasible, they're better solutions than my original (I just don't know whether either are technically do-able in your work environment.) – Kevin Nov 03 '17 at 13:21