Reputation: 3848
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 :
project/textFiles/textFile1.txt
...
project/mp3Files/mp3File1.txt
...
how do I access these files ? the general filestream / streamreader ....doesn't seem to be working.
Upvotes: 1
Views: 1235
Reputation: 29153
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.
Upvotes: 1
Reputation: 109189
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.
Upvotes: 1
Reputation: 47779
they get packaged up into the .xap file which gets deployed
Upvotes: -1