c# - Using .sqlite3 file to create a database on Windows Phone 8 -
i've been trying out sqlite on windows phone using tutorial base http://code.msdn.microsoft.com/wpapps/using-sqlite-with-wp8-52c3c671 , in it, database created in app.xaml this
string dbpath = path.combine( windows.storage.applicationdata.current.localfolder.path, "db.sqlite"); if (!fileexists("db.sqlite").result) { using (var db = new sqliteconnection(dbpath)) { db.createtable<person>(); } } private async task<bool> fileexists(string filename) { var result = false; try { var store = await windows .storage.applicationdata.current.localfolder .getfileasync(filename); result =true; } catch { } return result; }
i have database.sqlite3 file database created, , added project on assets folder. how can use file create database on windows phone app ?
add database.sqlite3 in solution. , make sure database.sqlite3 build action property set 'content'. below code lot use created database file in wp8 apps.
string dbpath = getdbpath(dbfilename);
edits
private async string getdbpath( string filename) { if (await doesfileexistasync(filename)) { // file exists; string dbpath = path.combine(windows.storage.applicationdata.current.localfolder.path, filename); } else { // file not exist storagefile databasefile = await package.current.installedlocation.getfileasync(filename); await databasefile.copyasync(applicationdata.current.localfolder); string dbpath=path.combine(windows.storage.applicationdata.current.localfolder.path, filename); } } private async task<bool> doesfileexistasync(string filename) { try { await applicationdata.current.localfolder.getfileasync(filename); return true; } catch { return false; } }
Comments
Post a Comment