[英]Including readme file to the compiled program
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.
主要思想是使程序成为仅一个.exe文件的独立程序。
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. 问题是如何将文本文件包含到已编译的.exe文件中,以及如何通过单击按钮将其打开。
So far I found how to embed a resource and read it as a stream using Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName)
. 到目前为止,我发现了如何使用
Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName)
嵌入资源并将其作为流读取。
Though, when I try read it through StreamReader
it returns System.ArgumentNullException
但是,当我尝试通过
StreamReader
读取它时,它返回System.ArgumentNullException
Stream streamS = Assembly.GetExecutingAssembly().GetManifestResourceStream(ProjectName.Properties.Resources.Readme); StreamReader rdr = new StreamReader(streamS); string text = rdr.ReadToEnd();
Add it as an Embedded Resource. 将其添加为嵌入式资源。 You can then access it with
Assembly.GetManifestResourceStream
. 然后,您可以使用
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
. 如果要在外部程序(如记事本)中打开它,则必须将其解压缩到一个临时文件(
Path.GetTempFileName
),然后使用Process.Start
启动Notepad.exe。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.