0

I have a small code that does some recalculations using text data provided. I also have written a readme file with the description of features and 'how-to' instructions. The main idea is to make the program standalone that is only one .exe file.

I did some googling, but found only how to work with external files or create installers.

The question is how to include a text file into the compiled .exe file and how to open it with a button click.

So far I found how to embed a resource and read it as a stream using Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName).
Though, when I try read it through StreamReader it returns System.ArgumentNullException

Stream streamS = Assembly.GetExecutingAssembly().GetManifestResourceStream(ProjectName.Properties.Resources.Readme); StreamReader rdr = new StreamReader(streamS); string text = rdr.ReadToEnd();

MrCheatak
  • 159
  • 7
  • 1
    Possible duplicate of [How to embed a text file in a .NET assembly?](https://stackoverflow.com/questions/433171/how-to-embed-a-text-file-in-a-net-assembly) – Peter B Feb 14 '19 at 10:30

1 Answers1

0

Add it as an Embedded Resource. You can then access it with Assembly.GetManifestResourceStream. If you want to show it in a window in your application, that's sufficient; if you want to open it in an external program, like Notepad, you'll have to extract it to a temporary file (Path.GetTempFileName), then start Notepad.exe with Process.Start.

canton7
  • 37,633
  • 3
  • 64
  • 77
  • I see it is indeed done using `Assembly`, but I'm stuck at `Assembly.GetExecutingAssembly().GetManifestResourceNames()` returning "Can't read memory". The file I embedded is in the Resources folder with "Embedded resource" property – MrCheatak Feb 16 '19 at 10:15
  • @MrCheatak add your full code and the full exception to your question? – canton7 Feb 16 '19 at 11:28
  • Just added where I was stuck with `Assembly`, but succeeded it another way around by using just `string text = ProjectName.Properties.Resources.Readme;` – MrCheatak Feb 16 '19 at 18:03