Hi all,
This code is using the FileHandler class added to the project, for the purposes of allowing the user to choose the folder.
I allow the user to "export" SQLite table data to a CSV file, as a backup data feature.
The user selects the folder and saves the file. The file name can be changed by the user.
I need to capture that user changed filename after the OS save file returns back to my app code.
That actual filename will be added to a SQLite backup table for history viewing reasons.
The HandleLoadResult function - If Result.Success Then - is always false.
So this function never is able to get to the code line:
s = File.ReadString(Result.Dir, Result.FileName)
Therefore, I'm unable to get the actual filename (Result.FileName) used in the saving of the file.
How can I get the actual user filename that is saved?
My code:
The code line: If Result.Success is always False, so it can't read the real user changed filename.
This code is using the FileHandler class added to the project, for the purposes of allowing the user to choose the folder.
I allow the user to "export" SQLite table data to a CSV file, as a backup data feature.
The user selects the folder and saves the file. The file name can be changed by the user.
I need to capture that user changed filename after the OS save file returns back to my app code.
That actual filename will be added to a SQLite backup table for history viewing reasons.
The HandleLoadResult function - If Result.Success Then - is always false.
So this function never is able to get to the code line:
s = File.ReadString(Result.Dir, Result.FileName)
Therefore, I'm unable to get the actual filename (Result.FileName) used in the saving of the file.
How can I get the actual user filename that is saved?
My code:
button code to save the file::
Private Sub btnBackup_Click
Dim Filename As String = "persons.csv"
Dim data As List = DBModule.GetAllPersons2
Dim count As Int = data.Size
If data.Size > 0 Then
'save as CSV file format
su.SaveCSV(Folder,Filename,",",data)
'now read the CSV file bytes
Dim b() As Byte = File.ReadBytes(Folder,Filename) '<==== this is the "default" Filename from line #2
Dim inp As InputStream
inp.InitializeFromBytesArray(b,0,b.Length)
'save to where the user wants to save the file
Wait For (fh.SaveAs(inp,"text/plain",Filename)) Complete (Success As Boolean) '<==== this is the "default" Filename from line #2
If Success Then
HandleLoadResult(fh.CheckForReceivedFiles)
DBModule.AddEventHistory("BACKUP",data.Size)
LoadEventHistory
MsgboxAsync(count & " Person records backed up." & CRLF & "Backup File: " & Filename,"Attention")
IME.HideKeyboard
Else
'ToastMessageShow("File not saved.", False)
End If
Else
MsgboxAsync("No Person records to backup.","Attention")
End If
End Sub
HandleLoadResult:
Private Sub HandleLoadResult(Result As LoadResult)
If Result.Success Then
Dim s As String
Try
s = File.ReadString(Result.Dir, Result.FileName)
Log("Result.FileName: " & Result.FileName)
ToastMessageShow($"File '${Result.RealName}' loaded"$, False)
Catch
s = "Error loading file"
Log(LastException)
End Try
xui.MsgboxAsync(s,"Attention")
End If
End Sub