简体   繁体   English

WinRT C#从文件夹资产加载sqlite数据库

[英]WinRT c# load a sqlite database from folder asset

I would like to load a prefab sqlite database from the folder Assets at the launch and copy it in the localstate of the application. 我想在启动时从Assets文件夹加载一个预制sqlite数据库,并将其复制到应用程序的localstate中。

I try a lot of thing and every time I have a "Access denied" or "file not found". 我尝试了很多事情,每次遇到“拒绝访问”或“找不到文件”时。

Have you any idea how to do it ? 你知道怎么做吗?

Regards 问候

This is a weird quirk for Win 8 RT. 这是Win 8 RT的怪癖。 I might guess that you have a special extension for your Sqlite db, like ".db" ... a workaround I have used is to use a ".txt" extension for the db in assets. 我可能会猜测您对Sqlite数据库有一个特殊的扩展名,例如“ .db”……我使用的解决方法是对资产中的数据库使用“ .txt”扩展名。

This works on my system without corrupting the file. 这可以在我的系统上运行而不会损坏文件。 I checked the db in Sqlite Database Browser. 我在Sqlite数据库浏览器中检查了数据库。

StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/db_in_assets.txt"));

await file.CopyAsync(ApplicationData.Current.LocalFolder, "db_in_local.db");

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

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