B4J Question How to tell windows to open a file with its default app?

MegatenFreak

Active Member
Licensed User
Hello.
My app creates Word and Excel output files. Currently it works if Office is installed in the default location (I give the file address directly to jShell), but otherwise it won't.
Is there a way to send the file to Windows so it automatically opens it with the default app for that type of file?
Thanks in advance.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
fx.ShowExternalDocument will not work in non-ui apps. A possible, Windows only, alternative that works in both types of apps:
B4X:
'Windows only!
'Opens MS Excel if it is installed.
'<code>Wait For (xl.OpenExcel(FilePath)) Complete (Success As Boolean)</code>
Public Sub OpenExcel (FilePath As String) As ResumableSub
    Dim shl As Shell
    shl.InitializeDoNotHandleQuotes("shl", "cmd.exe", Array("/c", "start", $""""$, $""${FilePath}""$))
    shl.Run(-1)
    Wait For shl_ProcessCompleted (Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String)
    If ExitCode <> 0 Then
        Log(StdOut)
        Log(StdErr)
        Return False
    End If
    Return True
End Sub
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…