[C# Helper]
Index Books FAQ Contact About Rod
[Essential Algorithms, Second Edition]

[The Modern C# Challenge]

[WPF 3d, Three-Dimensional Graphics with WPF and C#]

[The C# Helper Top 100]

[Interview Puzzles Dissected]

[C# 24-Hour Trainer]

[Beginning Software Engineering]

[C# 5.0 Programmer's Reference]

[MCSD Certification Toolkit (Exam 70-483): Programming in C#]

Title: Make a text file a project resource in C#

[Make a text file a project resource in C#]

This is handy for including a large amount of text as a project resource instead of putting the text directly in the code or 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.

// Load the file resource. private void Form1_Load(object sender, EventArgs e) { txtQuotes.Text = Properties.Resources.Twain; txtQuotes.Select(0, 0); }

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.

Download the example to experiment with it and to see additional details.

© 2009-2022 Rocky Mountain Computer Consulting, Inc. All rights reserved.