daChizzle
daChizzle

Reputation: 231

Reading Linked Text File From Resources with StreamReader

I have seen many examples that show StreamReader taking the arugment "Properties.Resources.someTextFile, and apparently they work great. However, in .net 4.5 I still get:

Error Message

//while not end of file, read lines of file and split into array
string myFile = Properties.Resources.data;

string line;

StreamReader reader = new StreamReader(myFile);

while ((line = reader.ReadLine()) != null)
{

    string[] array = line.Split('#');

    string tickerSymbol = array[0];

    string regPattern = array[1];

....

Resources

So, what am I doing wrong?

Upvotes: 1

Views: 1096

Answers (1)

TMS
TMS

Reputation: 126

By accessing the data text file resource through Properties.Resources the resulting variable myFile should contain the string contents of the file.

string myFile = Properties.Resources.data;

var lines = myFile.Split(new[] { Environment.NewLine }, StringSplitOptions.None);

foreach(var line in lines)
{
     // Process each line...
}

Upvotes: 2

Related Questions