So far I have used the code from the documentation of SaveFileDialog (https://documentation.xojo.com/api/user_interface/desktop/savefiledialog.html) to call the other correct method based on the file extension. This also works without problems under macOS/Windows.
Then yesterday, I tried the code on Linux (Mint 19.2, Fedora 28, Deepin 15.11, Elementary) and found that the code does not fire because FolderItem.Name is returned without a file extension despite the file extension being set (dropdown list in dialog). Does anyone have a suggestion on how I can achieve consistency on Linux?
My code:
Var dlg As New SaveFileDialog
dlg.InitialFolder = SpecialFolder.Desktop
dlg.Filter = FileTypeGroup1.Pdf + FileTypeGroup1.PlainText
Var file As FolderItem
file = dlg.ShowModalWithin(Self)
If Not (file Is Nil) Then
#Pragma Warning "Linux does not add the extension in file.Name - So Action-Event doesn't work."
Var sName As String = file.Name
If sName.Right(3) = "pdf" Then
' PDF Method
ElseIf sName.Right(3) = "txt" Then
' TXT Method
End If
End If
Var dlg As New SaveFileDialog ' OpenFileDialog works as expected.
dlg.InitialFolder = SpecialFolder.Desktop
dlg.Filter = FileTypeGroup1.All ' or
' dlg.Filter = FileTypeGroup1.Pdf + FileTypeGroup1.Rtf
Var file As FolderItem
file = dlg.ShowModalWithin(Self)
If Not (file Is Nil) Then
Var sName As String = file.DisplayName
System.DebugLog sName
System.DebugLog file.Name
System.DebugLog file.NativePath
System.DebugLog file.ShellPath
System.DebugLog file.URLPath
If sName.Right(3) = "rtf" Then
' Do something. Won't break.
Break
Elseif sName.Right(3) = "pdf" Then
' Do something. Won't break.
Break
End If
End If
Sorry to say, it’s a bug. FolderItem.Name is what I used before FolderItem.DisplayName as you can see in my first post and if you look in the DebugLog, you’ll see FolderItem.Name also returns the Name without Extension, also like all FolderItem...Path properties. I tested this into the deep with four different Linux OS. We’ll see what @William_Yu can do.