BLOG.CSHARPHELPER.COM: Embed a text file in a project as a resource in C#
Embed a text file in a project as a resource in C#
This is handy for including a large amount of text in a project without adding it within the code and without including a file in the program's installation package.
Open the Project menu and select Properties. Open the Add Resource dropdown and select Add Existing File. Select the text file and click Open.
Now the code can use it at run time as shown in the following code.
In this example the text file is called Twain.txt so the program can get its text from Properties.Resources.Twain.
That's all there is to it. A simple trick but sometimes useful.
Comments