Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read files with Build Action = Content

I have some files in my project that have Build Action set to Content.

How can I obtain a stream to read these content files?

PS: Setting the Build Action to Resource and then reading the file via Application.GetResourceStream() is not an option.

like image 513
thumbmunkeys Avatar asked Apr 27 '12 18:04

thumbmunkeys


2 Answers

Items with Build Action of Content are included in the package (.xap) file and are accessible via a Uri. You still use Application.GetResourceStream() to get at a stream

var si = Application.GetResourceStream(new Uri("FileName.ext", UriKind.Relative));
using (var sr = new StreamReader(si.Stream))
{
    //blah
}

This is fairly well documented in the MSDN help. Application.GetResourceStream

like image 100
Ritch Melton Avatar answered Dec 14 '22 13:12

Ritch Melton


You can see a full sample in the MSDN Code Gallery I posted recently, showing how to access files deployed along with the application by using the Application.GetResourceStream() method.

like image 31
Pedro Lamas Avatar answered Dec 14 '22 12:12

Pedro Lamas