我有 XAML Metro 应用程序。我需要部署一个静态文件,以便在每次应用程序启动时读取。我只能访问某些路径(例如 LocalStorage 和 InstalledLocation...是这样吗?)
如何让 VS 2012 将该文件(rtf 文档)部署到应用程序可以读取的位置?
最佳答案
一个好的解决方案是将文件放置在 VS 解决方案的 Assets 子文件夹中并通过以下方式访问:
Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(@"Assets\file.rtf")
Documentation from Microsoft on InstalledLocation
例如
var file = await Windows.ApplicationModel.Package.
Current.InstalledLocation.GetFileAsync(@"Assets\file.rtf");
result = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);
以下博客文章很好地演示了:
http://blogs.msdn.com/b/metroapps/archive/2012/07/15/access-your-application-assets-folder.aspx
这里也有很好的信息:
http://blog.jerrynixon.com/2012/06/windows-8-how-to-read-files-in-winrt.html
关于c# - 如何将文件从 Visual Studio 部署到 XAML Metro 应用程序中的可访问文件夹?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14414500/