Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/svn/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows phone 8 Windows Phone 8选择文本文件C#_Windows Phone 8_Text Files_Streamreader_Isolatedstorage - Fatal编程技术网

Windows phone 8 Windows Phone 8选择文本文件C#

Windows phone 8 Windows Phone 8选择文本文件C#,windows-phone-8,text-files,streamreader,isolatedstorage,Windows Phone 8,Text Files,Streamreader,Isolatedstorage,我有个问题。是否有可能在VisualStudio的WindowsPhone8上创建按钮事件来读取文本文件?我知道streamReader,如果我声明了我想要读取的wchich文件,但是如果我想从我想要显示的wchich文件列表中进行选择。我在网上做了研究,但没有找到答案。我知道我可以使用isolatedStorage来读取音乐、视频、图像,但不能读取文本文件。在应用程序上,我创建了几个包含文本的文件,我希望用户能够从该文件中显示一个,无论他们想看到哪个。那么,您能告诉我如何做到这一点吗?在Win

我有个问题。是否有可能在VisualStudio的WindowsPhone8上创建按钮事件来读取文本文件?我知道streamReader,如果我声明了我想要读取的wchich文件,但是如果我想从我想要显示的wchich文件列表中进行选择。我在网上做了研究,但没有找到答案。我知道我可以使用isolatedStorage来读取音乐、视频、图像,但不能读取文本文件。在应用程序上,我创建了几个包含文本的文件,我希望用户能够从该文件中显示一个,无论他们想看到哪个。那么,您能告诉我如何做到这一点吗?

在Windows Phone 8.1中,允许使用文件选择器,其功能与您期望的相同,因此您可能希望将应用升级到WP8.1


下面是有关此API的更多信息:

您可以使用
IsolatedStorage
读取任何您想要的文件类型。您一定使用了类似于
启动器的东西,它根据选择器过滤出文件类型

您可以像这样打开一个文件:

private async Task ReadTextFile(字符串文件名)
{
//返回缓冲区
字符串文件_content=“”;
//获取本地文件夹
StorageFolder local=Windows.Storage.ApplicationData.Current.LocalFolder;
如果(本地!=null)
{
//获取文件
存储文件;
尝试
{
file=await local.GetFileAsync(文件名);
}
捕获(例外情况除外)
{
//没有文件,返回空
返回文件内容;
}
//得到溪流
System.IO.Stream file_Stream=wait file.OpenStreamForReadAsync();
//读取数据
使用(StreamReader StreamReader=新StreamReader(文件\流))
{
file_content=streamReader.ReadToEnd();//读取全文文件
streamReader.Close();
}
//关闭小溪
文件_stream.Close();
}
//返回
返回文件内容;
}

如果要获取PackageLocation(添加到项目中的文件,如资产和图像),请将
LocalFolder
替换为

Windows.ApplicationModel.Package=Windows.ApplicationModel.Package.Current;
Windows.Storage.StorageFolder installedLocation=package.installedLocation;