Reputation: 1381
I am currently building a Windows Phone 8 Application but I am struggling with the following problem. Although I can access to any text files on my computer , I cannot access to a text file that I created in the resource folder that I created in my application.
Does anyone know how to access to a textfile in a folder that belongs to the application ande then use the streamReader to read it?
Thank You Very Much For Your Help !
Upvotes: 1
Views: 732
Reputation: 136
You use the Application.GetResourceStream method passing in the Uri of the file, in order to access the StreamResourceInfo object returned, which has the Stream property for you to access (which you can then pass to StreamReader and so on).
As to the Uri, it depends on what Build Action (from the Properties window) you have set for this file, ie. whether it is Resource or Content.
If it's a Resource, then the Uri should be:
new Uri("/AssemblyName;component/path/file.txt", UriKind.Relative);
If it's a Content, then the Uri should be:
new Uri("path/file.txt", UriKind.Relative);
Note that the 'AssemblyName' is the name of the assembly for which the project that contains the file. And that the 'path' is the forwardslash-separated path into the file within the project taking into account the folder and subfolders it is in.
Upvotes: 3