Reading Files Using Action Action = Content

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

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

PS: Setting Build Action to Resource and then reading the file using Application.GetResourceStream() not a parameter.

+6
source share
2 answers

Elements with Build Action of Content are included in the package file (.xap) and are accessible through Uri . You are still using Application.GetResourceStream() to get the stream

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

This is fairly well described in the MSDN Help. Application.GetResourceStream

+10
source

You can see the full sample in the recently published MSDN code gallery, which shows how to access files deployed with the application using the Application.GetResourceStream () method .

+3
source

Source: https://habr.com/ru/post/914369/


All Articles