views:

51

answers:

2

I'm trying to include a text file that contains some static data that I need to read in when the app starts up. I've added the file and marked the Build Action to "Resource" but I'm unsure of how to actually read it in as a stream. Anyone know how to do this?

+4  A: 

You can use the System.Windows.Application.GetResourceStream method:

var resource = System.Windows.Application.GetResourceStream(new Uri("textfile.txt", UriKind.Relative)

should do the trick

Mark
A: 

Hi Mark,

It doesnt work for me. The resource is not initilize, the GetResourceStream return null.

Here is my code :

var resource = System.Windows.Application.GetResourceStream(new Uri("Stations.txt", UriKind.Relative));

StreamReader sr = new StreamReader(resource.Stream);
Skilpit