Windows Phone 从文本文件中读取 [英] Windows Phone read from text file

查看:25
本文介绍了Windows Phone 从文本文件中读取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个应用程序,它从文本文件中读取数据并将其用作应用程序的基础.这只是一个简单的文本文件,其中包含程序所需的几行数据.我已将文本文件作为 Visual Studio 项目的一部分包含在内.但是,当我尝试运行应用程序并使用 StreamReader 读取文本文件时,它会引发错误:

I'm writing an app that reads data from a text file and uses that as the basis of the app. This is just a simple text file with several lines of data that the program needs. I've included the text file as part of the project in visual studio. However, when I try to run the app and read the text file using a StreamReader, it throws an error:

System.MethodAccessException:尝试通过安全透明方法App.MainPage..ctor()"访问安全关键方法System.IO.File.Exists(System.String)"失败.在 System.IO.File.Exists(String path)"

"System.MethodAccessException: Attempt by security transparent method 'App.MainPage..ctor()' to access security critical method 'System.IO.File.Exists(System.String)' failed. at System.IO.File.Exists(String path)"

此文本文件对应用程序的功能非常重要.当人们下载它并直接从应用程序中读取它时,有什么方法可以将它包含在 XAP 中?

This text file is very important to the function of the app. Is there any way I can include it with the XAP when people download it and read it directly from within the app?

推荐答案

这是从 wp7 应用程序中的解决方案读取文本文件的解决方案.

Here is the solution to read a text file from solution in wp7 app.

  1. 复制解决方案中的文本文件.

  1. Copy text file in your solution.

右键单击 -> 属性

现在将构建操作设置为资源.

Now set Build Action to Resource.

System.IO.Stream src = Application.GetResourceStream(new Uri("solutionname;component/text file name", UriKind.Relative)).Stream;
            using (StreamReader sr = new StreamReader(src))
              {
                 string text = sr.ReadToEnd();
              }

这篇关于Windows Phone 从文本文件中读取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆