在Windows 8中读取文本文件

本文关键字:取文本 文件 读取 Windows | 更新日期: 2023-09-27 18:27:23

我在windows-8中读取嵌入资源(文本文件)时遇到了一些问题,通常我使用Assembly.GetExecutingAssembly(),但在本例中似乎无法做到这一点。我正在引用System.Reflection命名空间,但它说找不到,认为它可能已被删除。

有什么想法吗?

当前使用Windows 8消费者预览

代码:Assembly readAssembly = Assembly.GetExecutingAssembly(); StreamReader streamReader = new StreamReader(readAssembly.GetManifestResourceStream("Test.txt"));

错误:System.Reflection.Assembly"不包含"GetExecutingAssembly"的定义

在Windows 8中读取文本文件

WinRT中,资源应包含在包中。使用Package.Current.InstalledLocation.GetFileAsync读取资源。

下面的帖子有一些示例代码:
http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/thread/d4b327e3-a8f2-4d3c-8ed7-ba2ea953d0b9

在AppStore库中,您可以使用以下代码:

Stream stream = this.GetType().GetTypeInfo().Assembly.GetManifestResourceStream(fileName);

为什么不使用VS 2012中提供的ReadFileAsync()方法。将文本文件添加到您的项目中,并调用异步方法