import already created sqlite database (xamarin)

后端 未结 1 1953
太阳男子
太阳男子 2021-01-26 06:49

I\'m using Xamarin and want to know how to import an sqlite database I\'ve already created. So far ive added it to the assets folder but dont know where to start next.

相关标签:
1条回答
  • 2021-01-26 07:17
    string localPath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), YourAppName);
    
    //Directory with your DB3 file
    var dirx = Android.OS.Environment.ExternalStorageDirectory.ToString();
    
    // DB File 
    var dbfile = System.IO.Path.Combine(dirx , "/YourAppName/YourSQLiteDB.db3");
    
    
    
                if (File.Exists(dbfile))
                {
    
                    File.Copy(dbfile, localPath, true);
                    Toast.MakeText(this, "SQLiteDB copied successfully!", ToastLength.Long).Show();
    
    
                }
                else
                {
                    Toast.MakeText(this, "copy from " + diry +         System.Environment.NewLine + "to " + localPath + " failed or source file is missing!", ToastLength.Long).Show();
                }
    }
    
    0 讨论(0)
提交回复
热议问题