使用Build Action = Content读取文件

thu*_*eys 6 windows-phone-7

我的项目中有一些Build Action设置为的文件Content.

如何获取流来读取这些内容文件?

PS:设置Build Actionto Resource然后通过文件读取Application.GetResourceStream()不是一个选项.

Rit*_*ton 10

带有Build Action的项目Content包含在包(.xap)文件中,可通过Uri.你仍然习惯于Application.GetResourceStream()获得一个流

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

这在MSDN帮助中有相当详细的记录.Application.GetResourceStream