Take the 2-minute tour ×

I wanted to access a few of my assets ... in particular, my app comes with a bunch of text files and mp3 files.

They are not downloaded from the net later, but come with the app itself. so I was wondering how the isolated storage comes into the picture if at all ?

all I want to do is read the text file / play the mp3 file. And these files come with the app itself. I know the location of the files relative to the project folder. some thing like :





how do I access these files ? the general filestream / streamreader ....doesn't seem to be working.

share|improve this question
The build process will output a your_project.xap file. This is just a zip-compressed file. Rename it to your_project.zip and you can open it up and see the internal structure. Also, you may need to specify UriKind.Relative when creating the Uri you want to load. –  jeffamaphone Jan 30 '11 at 23:39
add comment

3 Answers

up vote 1 down vote accepted

Mark your .txt files as "Content" and then use code like the following:

Uri uriMyFile = new Uri("myfilename.txt",UriKind.relative);
StreamReader sr = new StreamReader((Application.GetResourcesStream(uriMyFile)).Stream);

the application class provides access to the appropriate stream.

share|improve this answer
That's GetResourceStream, only one resource. –  Léon Pelletier Apr 17 '13 at 16:22
That's right. Feel free to edit –  Todd Main Apr 17 '13 at 17:21
I actually don't know how to edit just one letter. –  Léon Pelletier Apr 17 '13 at 18:20
add comment

Say you have a Resources folder under your project's root directory. Make sure that the Build Action (in the Properties window) for all files under this folder that you want to access is set to Content and the Copy to Output Directory option is set to Copy if Newer or Copy Always.

I've never tried to read a text file, but I am loading an XML file that is packaged with my app as follows:

XDocument doc = XDocument.Load( "Resources/MyData.xml" );

I think I remember having problems if I used a leading / in the path.

share|improve this answer
add comment

they get packaged up into the .xap file which gets deployed

share|improve this answer
yes. but how to I access it in code ? –  Egon Jan 30 '11 at 21:38
add comment

Your Answer


