How to embed a text file in a .NET assembly?

Right-click the project file, select Properties.

In the window that opens, go to the Resources tab, and if it has just a blue link in the middle of the tab-page, click it, to create a new resource.

enter image description here

Then from the toolbar above the tab-page, select to add a new text file, give it a name, it will be added to your project and opened up.

If you get this far, then in your code you can type in Resources.TheNameYouGaveTheTextFileHere and you can access its contents. Note that the first time you use the Resources class in a class, you need to add a using directive (hit Ctrl+. after typing Resources to get the menu to get VS to do it for you).

If something was unclear about the above description, please leave a comment and I’ll edit it until it is complete or makes sense 🙂

Leave a Comment