Search code examples
c#diskchm

Create file with FileOptions.DeleteOnClose, write to it and see it getting deleted after


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.


Solution

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