How to browse for a folder at install time

ImportantThe following article uses options that are available starting with the Enterprise edition and project type.

It might be required to allow the user to select a second folder during the installation, in addition to the Application Folder. In order to achieve this you would need to implement the functionality provided by the predefined "FolderDlg" dialog, as described below.

Download and unzip the Browse For Folder example project to better understand how to configure your own package. The Enterprise or Architect edition of Advanced Installer is required in order to build and run the project.

Follow the steps presented below:

1. In the Install Parameters page define a public property (uppercase letters only), named MY_DIR (for example).

2. In the Files and Folders page, create a property-based folder using the property defined above. Add files/folders under this property-based folder.

3. In the Custom Actions page, create a "Set installer property" custom action with sequence before the "Wizard Dialogs Stage -> Searches" action group. Use the following options for this custom action:

a) Property: MY_DIR (defined in the "InstallParameters" page)

b) Value: [WindowsVolume]

5. Copy this custom action before "Install Execution Stage -> Searches" action group, by dragging & dropping it there (keeping the SHIFT key pressed).

6. Click on the "Advanced execution scenarios..." blue link and select the "Skip action in Install Execution Stage if executed in Dialogs Stage" option.

7. Switch to the Dialogs page, right-click on "FolderDlg" dialog and select "New Dialog" from the context-menu. A new dialog will be created in the tree control - name it "MyFolderDlg" for example. You can also select an existing dialog instead of creating a new one.

8. Add a "Path Edit" control and a "Button" control on this dialog. Set the text of the button to: "[ButtonText_Browse]"

9. Set the property attached to the "Path Edit" control to "MY_DIR".

10. For the button define the following control events in the "Published Events" tab (the first control event is a "Set installer property value" event):

EventArgument
[_BrowseProperty]MY_DIR
Display a specific child dialogBrowseDlg

11. For the "Next" button from the dialog add a "Verify and set the selected folder path" published event specifying "MY_DIR" as its Argument:

EventArgument
Verify and set the selected folder pathMY_DIR

Warning!In the absence of this Control Event, the sub-folders of the "MY_DIR" directory will be installed in the wrong location (usually in the root of the system drive) if the user enters the folder manually in the "Path Edit" control (instead of using the "Browse" button to select it). This event is required such that the installer is notified that the path has changed.

NoteAlso note that the Argument is "MY_DIR" and NOT the Formatted Type value "[MY_DIR]".

NoteTo prevent the user writing a folder which doesn't exist on target machine you can set the "Enabled" attribute of "MY_DIR" control to False.