我的 UWP 应用无法读取 txt 文件 [英] My UWP app won't read a txt file

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

问题描述

我想知道是否有人知道如何让通用 Windows 应用程序读取 txt 文件.

I was wondering if anyone would know how to get an Universal Windows app to read a txt file.

StreamReader lezer = new StreamReader(@"C:\Users\LotteDiesveld\Documents\Visual Studio 2015\Projects\Jaar 1\Periode 2\OIS 12\Eindopdracht\Personen.txt");
tbPersonen.Items.Add(lezer.ReadToEnd());

我也试过这个

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

我知道关于这个主题已经给出了多个答案,但都没有奏效,因为我不断收到错误消息.此错误是无法将类型字符串转换为类型 uri"或无法将类型字符串转换为类型流".

I know multiple answers have been given on this subject, but none work, because I keep getting an error. This error is either "Cannot convert type string to type uri" or "cannnot convert type string to type stream".

推荐答案

UWP 应用在沙盒环境中运行,无权从硬盘驱动器上的任何位置读取文件.如果您想读取用户文档库中的文件,您应该让用户使用选择器选择文件或在应用程序清单中声明文件夹.有关更多信息,请参阅 Jerry Nixon 的博客文章:http://blog.jerrynixon.com/2012/06/windows-8-how-to-read-files-in-winrt.html

A UWP app runs in a sandboxed environment and has no permissions to read a file from anywhere on the hard drive. If you want to read a file in the user's Documents Library you should either let the user select the file using a picker or declare the folder in the application's manifest. Please refer to Jerry Nixon's blog post for more information: http://blog.jerrynixon.com/2012/06/windows-8-how-to-read-files-in-winrt.html

另请参考以下类似问题:

Please also refer to the following similar question:

Windows 10 通用应用文件/目录访问

有关如何读取与您的应用一起分发的文件的信息,请参阅此处的答案:

For information about how to read a file that is distributed along with your app, please see the answer here:

如何在 windows 通用中读取文本文件应用

这篇关于我的 UWP 应用无法读取 txt 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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