[英]How to read a file shipped with the app in Windows 8 Metro
我的應用程序附帶了一個文本文件,我想在屏幕上顯示其內容。 有人知道該怎么做嗎? 通常的文件IO似乎不適用於Metro。
謝謝
不知道您嘗試了什么,但請查看以下內容:
有了StorageFolder,您便擁有了一整套讀取/寫入文件的功能。
在我的應用程序中,我正在讀取應用程序隨附的XML文件,您可以對其進行調整以讀取任何類型的文件
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
希望能有所幫助
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.