码迷,mamicode.com
首页 > 数据库 > 详细

xamarin SQLite路径

时间:2016-08-09 11:57:07      阅读:515      评论:0      收藏:0      [点我收藏+]

标签:

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);
        }

 

xamarin SQLite路径

标签:

原文地址:http://www.cnblogs.com/zuimengaitianya/p/5752535.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!