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.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With