Since many years (20?) I use to use the following Basic code for a simplified file picker. It is simplified because it uses one filter string allowing a single file selection. This is the simplification I need in 99% of all practical use cases.
Function pickFile(sTitle$, sInit$, sFilterLabel$, sPattern$) As String
REM return a single file URL or ""
REM dialog starts at office default directory if sInit = ""
Dim oPicker, x()
oPicker = CreateUnoService("com.sun.star.ui.dialogs.FilePicker")
oPicker.setTitle(sTitle)
oPicker.setDisplayDirectory(sInit)
oPicker.setMultiSelectionMode(False)
oPicker.appendFilter(sFilterLabel, sPattern)
if oPicker.execute() then
x() = oPicker.getFiles()
pickFile = x(0)
endif
End Function
And for the sake of completness:
Function pickFolder(sTitle$, sInit$) AS String
REM return folder URL or ""
REM dialog starts at office default directory if sInit = ""
Dim oPicker
oPicker = CreateUnoService("com.sun.star.ui.dialogs.FolderPicker")
oPicker.setTitle(sTitle)
oPicker.setDisplayDirectory(sInit)
if oPicker.execute() then
pickFolder = oPicker.Directory
endif
End Function
Both functions return a file URL or an empty string in case of cancel.