Read text file from C# Resources

Dobz picture Dobz · Mar 30, 2013 · Viewed 54.4k times · Source

I need to read a file from my resources and add it to a list. my code:

private void Form1_Load(object sender, EventArgs e)
{
    using (StreamReader r = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream("myProg.myText.txt")))
    {
        //The Only Options Here Are BaseStream & CurrentEncoding
    }
}

Ive searched for this and only have gotten answers like "Assembly.GetExecutingAssembly...." but my program doesnt have the option of Assembly.?

Answer

Parimal Raj picture Parimal Raj · Mar 30, 2013

Try something like this :

string resource_data = Properties.Resources.test;
List<string> words = resource_data.Split(new[] {Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries).ToList();

Where

enter image description here