Metro中读取应用程序附带的文件

Metro中读取应用程序附带的文件

本文介绍了如何在Windows 8 Metro中读取应用程序附带的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序附带了一个文本文件,我想在屏幕上显示其内容.有人知道该怎么做吗?通常的文件IO似乎不适用于Metro.

I've got a text file that ships with my app and I want to display its contents on the screen. Anyone know how to do that? The usual file IO doesn't seem to work for Metro.

谢谢

推荐答案

在我的应用程序中,我正在读取该应用程序随附的XML文件,您可以对其进行调整以读取任何类型的文件

In my app I am reading a XML file that comes with the app, you can tweak it to read any type of file

public class LocalStorage
{
    private const string SyndicationFeedCategoriesFileName = "FeedCategories.xml";

    private StorageFile _storageFile;
    private StorageFolder _storageFolder;
    public async Task<XmlDocument> Read_categories_from_disk()
    {

        try
        {
            _storageFolder = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFolderAsync("Xml");
            _storageFile = await _storageFolder.GetFileAsync(SyndicationFeedCategoriesFileName);

            var loadSettings = new XmlLoadSettings
                                   {ProhibitDtd = false, ResolveExternals = false};
            return await XmlDocument.LoadFromFileAsync(_storageFile, loadSettings);
        }
        catch (Exception)
        {
            return null;
        }
    }
}

在此处查看完整的源代码 http://metrorssreader.codeplex.com/SourceControl/changeset/view/18233#263004

View the full source code here http://metrorssreader.codeplex.com/SourceControl/changeset/view/18233#263004

希望有帮助

这篇关于如何在Windows 8 Metro中读取应用程序附带的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 22:28