'Exporting data to CSV file.
Sub BtnExpSiteList_Click
'Creates a CSV file in DirInternal from SQLite DB
Private listosites As List
Private ExportFile As StringUtils
If File.Exists(File.Dirinternal&"/ABT/", "") = False Then File.MakeDir(File.Dirinternal&"/ABT/", "")
If File.Exists(File.Dirinternal&"/ABT/", "expsitelist.csv") Then File.Delete(File.Dirinternal&"/ABT/", "expsitelist.csv")
'Create List from SQL1
listosites = DBUtils.ExecuteMemoryTable(SQL1, "SELECT * FROM sites", Null, 0)
If listosites.Size > 0 Then
ExportFile.SaveCSV(File.Dirinternal&"/ABT/", "expsitelist.csv", ",", listosites)
CSVpexport_click
Else
toast.Show("No sites in list. No export.")
Return
End If
End Sub
Sub CSVpexport_click
'Converts CSV file to Byte array and streams to SDCard
Private b2() As Byte = File.ReadBytes(File.Dirinternal&"/ABT/", "expsitelist.csv")
Private input As InputStream
toast.Initialize(pnlABDispLatLng)
toast.VerticalCenterPercentage = 18
toast.DurationMs = 2000
input.InitializeFromBytesArray(b2, 0, b2.Length)
Wait For (FileHandler1.SaveAs(input, "text/csv", "SQL.csv")) Complete (success As Boolean)
If success Then
toast.Show("Data exported successfully")
Else
toast.Show("Data not exported")
End If
kb.HideKeyboard
End Sub