Why won't my program recognize a text file?
Okay, so I have a text file called "Source.txt" and it contains code that needs to be read by my program.
I created Source.txt within a folder called "Resources" in my project, I created it, and currently its holding a couple resources.
In Form1开发者_开发问答, I'm trying to put the text in Source.txt into a string variable, like so:
string s = Properties.Resources.Source;
However, when I do that, it comes up with the error:
does not contain a definition for 'Source'
How do I fix it?
Chris Lively answered it in the comments:
You can't use ".txt" files as resource files. .Net resource files are XML files with a very > particular structure. If you need a resource file, right click on your project name and > click "properties" then go to the Resources tab. Add the strings you need
Here's what I did.
Step 1: Right click my project name, select Properties.
Step 2: Select the Resources tab in the properties window.
Step 3: Select the down arrow next to "Add Resource".
Step 4: Select "Add New Text File"
Step 5: Named the text file, added in what I wanted to the text file.
Its working great, thanks to all who contributed.
精彩评论