Search code examples
c#file-ioresourcesstreamreader

Read text file from C# Resources


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.?


Solution

  • 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