c# - 如何从项目路径获取 WinRT 中的文件?

标签 c# windows-runtime directory

我想将数据文件添加到我的项目中。这些文件将来不会更改。我可以在项目结构中的什么位置放置它们?我试图将它们放入 Assets ,但有时它们会从那里消失。我应该把它们放在哪里?

最佳答案

检查文件文件夹的属性(通过 visual studio)并检查“Build Action”是否设置为 Content,“Copy to Output Directory”是否设置为“Copy Always”

enter image description here

要读取此文件,请使用:

var folder = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFolderAsync("MyFolder");
var file = await folder.GetFileAsync("MyFile.txt");

if (file != null)
{
    var content = await FileIO.ReadTextAsync(file);
}

来源:Windows 8: The right way to Read & Write Files in WinRT

关于c# - 如何从项目路径获取 WinRT 中的文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21500336/

相关文章:

c# - 在 Windows 7 中使用 C# 运行 Selenium 测试时出现 "IEDriverServer does not exist"错误

c# - Setter 注入(inject)或环境上下文模式

c# - 如果值是枚举值的一部分,则查找值

windows-8 - 如何实现 Metro 风格应用的 UI 自动化?

php - 创建了 apache 别名目录,但不工作

c# - 错误 : The given path's format is not supported

sql-server - WinRT System.Data - 连接到 SQL

c# - Windows Phone 8.1 VibrationDevice 不会停止振动

swift - 在 OS X swift 3.0 中设置删除文件的权限

在 C 中使用循环创建目录和文件