简体   繁体   English

如何将数据文件添加到Windows Universal应用

[英]How to add data file to Windows Universal app

I am working on a Universal app, initially targeting Windows Phone 8.1. 我正在开发通用应用程序,最初针对Windows Phone 8.1。

I have an XML file that I would like to package/ship along with the app, which the app will read when it's being run and will also update it. 我有一个XML文件,希望与该应用程序一起打包/运输,该应用程序在运行时将读取并更新。

I've found examples of how to read and save to a local folder but nothing about how to ship data along with the app and read it. 我找到了有关如何读取和保存到本地文件夹的示例,但没有关于如何将数据与应用程序一起读取和读取的示例。

Should the XML file be added as a resource? 应该将XML文件添加为资源吗? Or should it be stored in the local folder? 还是应该将其存储在本地文件夹中? If so, how do I add the file to that folder ahead of time? 如果是这样,我如何提前将文件添加到该文件夹​​? In a previous app I added XML files as resources, however that app was for Windows Phone 8 and the Universal apps seem to have changed how a lot of things are done so I am not sure what the best option is here. 在以前的应用程序中,我将XML文件添加为资源,但是该应用程序是用于Windows Phone 8的,而Universal应用程序似乎已经改变了很多事情,因此我不确定这里最好的选择是什么。

What's the best way to do this? 最好的方法是什么?

Thanks! 谢谢!

The only way to ship data with the app is to include it in appx package by adding it to your project and marking it as content. 随应用程序一起运送数据的唯一方法是将数据添加到项目中并将其标记为内容,从而将其包含在appx包中。 This will place it in the app's read-only install directory. 这会将其放置在应用程序的只读安装目录中。

To update the file you'll need to copy it to the application data folders. 要更新文件,您需要将其复制到应用程序数据文件夹中。 I'd probably write an access function to get the file which loads it from the local folder if it exists there. 我可能会编写一个访问函数来获取从本地文件夹加载文件的文件(如果存在)。 If not, then copy it over. 如果没有,则将其复制过来。

--Rob - 抢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM