Windows 10 通用应用程序中的 StreamReader [英] StreamReader in Windows 10 Universal App

查看:41
本文介绍了Windows 10 通用应用程序中的 StreamReader的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从 Windows 10 通用应用程序中的 XML 文件中读取数据.StreamReader 仅将 Stream 作为参数.我曾经在 WinForms、WPF 或 MVC 中使用文件路径执行此操作,但我不知道如何在 Windows 10 通用应用程序中执行此操作.

I am trying to read from a XML file in Windows 10 Universal App. StreamReader only takes Stream as argument. I used to do this with the file path in WinForms, WPF or MVC but I don't know how to do it in Windows 10 universal app.

TextReader reader = new StreamReader(@"C:\Users\User\documents\visual studio 2015\Projects\SQLiteApp\SQLiteApp\SomeFile.xml");

推荐答案

确实,Windows 10 和沙箱在读取/写入的位置方面存在许多限制.

Indeed, Windows 10 and the sandbox has many limitations in where you can read from/write to.

这不是 Windows 10 应用程序问题",而是 Windows 应用商店应用程序 Api 更改.在 Windows 应用商店应用程序中读取文件的常用方法是使用 StorageFile:

This is not a Windows 10 App "Problem", but a Windows Store App Api change. A common way to read a file in a Windows Store App is to use the StorageFile:

 StorageFile file = 
      await StorageFile.GetFileFromApplicationUriAsync("ms-appx:///yourFile.txt");

看看这篇文章,获取有关在 Windows 10 中读取文件的更多信息.

Take a look at this post, to get more information about reading files in windows 10.

这篇关于Windows 10 通用应用程序中的 StreamReader的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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