B4J Tutorial Associating files with your app

Discussion in 'B4J Tutorials' started by Erel, Jun 23, 2019.

  1. Erel

    Erel Administrator Staff Member Licensed User

    Follow these steps to associate files, based on their extension, with your app. The user will be able to double click on a file and your app will be opened with the selected file.

    Step 1: Make sure to use Java 11 with B4JPackager11 v1.10+.
    Step 2: Add the code to handle the selected file.
    Example:
    Code:
    Sub AppStart (Form1 As Form, Args() As String)
       MainForm = Form1
       MainForm.RootPane.LoadLayout(
    "1")
       MainForm.Show
       
    If Args.Length > 0 Then
           
    Try
               
    If File.Exists(Args(0), ""Then 'don't assume that it is a valid path
                   ListView1.Items.AddAll(File.ReadList(Args(0), ""))
               
    End If
           
    Catch
               
    Log(LastException)
           
    End Try
       
    End If
    End Sub
    Step 3: You need to modify InstallerScript-Template.iss file that is created when you run B4JPackager11.
    The following code should be added:
    Code:
    [Registry]
    Root: HKCR; SubKey: .lst; ValueType: 
    string; ValueData: My List Files; Flags: uninsdeletekey noerror; Tasks: ; Languages:
    Root: HKCR; SubKey: My 
    List Files; ValueType: string; ValueData: My List Files; Flags: uninsdeletekey noerror
    Root: HKCR; SubKey: My 
    List Files\Shell\Open\Command; ValueType: string; ValueData: """{app}\{#MyAppExeName}"" ""%1"""; Flags: uninsdeletevalue noerror
    Root: HKCR; Subkey: My 
    List Files\DefaultIcon; ValueType: string; ValueData: {app}\{#MyAppExeName},0; Flags: uninsdeletevalue noerror
    It will associate files with .lst extension with your app. The file description will be My List Files.

    The template file will be recreated every time that you run B4JPackager11. Make sure to copy it outside of the temp folder.
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    upload_2019-6-23_10-52-4.gif
     
    Peter Simpson and JOTHA like this.
  3. Peter Simpson

    Peter Simpson Expert Licensed User

    Absolutely brilliant @Erel, this is just what the doctor ordered and just in the nick of time too :)

    Thank you...
     
    Erel and DonManfred like this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice