标签:
xamarin使用SQLite时对应的访问路径各个平台不一样,需要单独引用。下面各平台罗列代码:
Windows8.1:
public SQLiteConnection GetConnection(string dbName) { var sqliteFilename = string.Format("{0}.db3", dbName); string documentsPath = global::Windows.Storage.ApplicationData.Current.LocalFolder.Path; var path = Path.Combine(documentsPath, sqliteFilename); return new SQLite.SQLiteConnection(path); }
UWP:
public SQLiteConnection GetConnection(string dbName) { var sqliteFilename = string.Format("{0}.db3", dbName); string documentsPath = global::Windows.Storage.ApplicationData.Current.LocalFolder.Path; var path = Path.Combine(documentsPath, sqliteFilename); return new SQLite.SQLiteConnection(path); }
Android:
public SQLite.SQLiteConnection GetConnection(string dbName) { var sqliteFilename = string.Format("{0}.db3", dbName); string documentsPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal); var path = Path.Combine(documentsPath, sqliteFilename); return new SQLite.SQLiteConnection(path); }
IOS:
public SQLite.SQLiteConnection GetConnection(string dbName) { var sqliteFilename = string.Format("{0}.db3", dbName); string documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal); // Documents folder string libraryPath = Path.Combine(documentsPath, "..", "Library"); // Library folder var path = Path.Combine(libraryPath, sqliteFilename); return new SQLite.SQLiteConnection(path); }
标签:
原文地址:http://www.cnblogs.com/zuimengaitianya/p/5752535.html