BrowseForFile doesn't display dialog - Advanced Installer Community

We’re moving our forums to a new platform.

You can still browse and search existing topics, but you can no longer create new topics or post replies.

For questions, technical issues, or feature requests, please don’t hesitate to contact our support team at support@advancedinstaller.com.

Thank you for your understanding!

ash_microsec
Posts: 38
Joined: Thu Dec 16, 2010 9:35 am
Location: Emsworth

BrowseForFile doesn't display dialog

So I've followed the instructions on the http://www.advancedinstaller.com/user-g ... -file.html tutorial and refered to the sample given, and my custom dialog's "Browse" button's Published Events are the same (albeit a different variable name). However, when I run the generated EXE and attempt to use the Browse button, I get a wait cursor, then no Browse dialog. I ran it using the "Run and Log" and can see the following in the log:

Code: Select all

Action 08:41:00: SQLBackupFileDialog. Dialog created
MSI (c) (B8:20) [08:42:14:785]: PROPERTY CHANGE: Adding AI_OFN_DLG_TITLE property. Its value is 'Select License File'.
MSI (c) (B8:20) [08:42:14:816]: PROPERTY CHANGE: Adding AI_OFN_FILTERS property. Its value is 'Backup Files (*.bak)|*.bak'.
MSI (c) (B8:20) [08:42:14:847]: PROPERTY CHANGE: Adding AI_OFN_FILEPATH property. Its value is 'C:\p4_PI-1091666_PI-126\AllDay\src_MSVS2K8\build\Backup\Test.bak\'.
MSI (c) (B8:20) [08:42:14:863]: Doing action: BrowseForFile
Action 08:42:14: BrowseForFile. 
Action start 08:42:14: BrowseForFile.
MSI (c) (B8:0C) [08:42:15:050]: Invoking remote custom action. DLL: C:\DOCUME~1\ASH~1.MIC\LOCALS~1\Temp\MSI2C.tmp, Entrypoint: BrowseForFile
MSI (c) (B8!18) [08:42:15:472]: PROPERTY CHANGE: Deleting AI_OFN_FILEPATH property. Its current value is 'C:\p4_PI-1091666_PI-126\AllDay\src_MSVS2K8\build\Backup\Test.bak\'.
MSI (c) (B8!18) [08:42:15:519]: PROPERTY CHANGE: Deleting AI_OFN_FILTERS property. Its current value is 'Backup Files (*.bak)|*.bak'.
MSI (c) (B8!18) [08:42:15:535]: PROPERTY CHANGE: Deleting AI_OFN_DLG_TITLE property. Its current value is 'Select License File'.
Action ended 08:42:15: BrowseForFile. Return value 1.
After some fiddling, I've found several issues here:

1. The default file path value is generated using a "Property set with Formatted" custom action (in "InstallUISequence\Begin") with the Formatted Text of "[SETUPEXEDIR]Backup\Test.bak", yet the returned value has a "\" on the end of it (seen in the log as "...\Test.bak\") which stops the Browse dialog finding the file. How do I stop this unwanted "\" being added?

2. If the file specified in the 'AI_OFN_FILEPATH' property does not exist, the Browse dialog is not displayed. Once I click the Browse button, how can I validate whether the file exists and if it doesn't, use the "[SETUPEXEDIR]" folder (without a "\") instead?

Thanks.

Ash
ash_microsec
Posts: 38
Joined: Thu Dec 16, 2010 9:35 am
Location: Emsworth

Re: BrowseForFile doesn't display dialog

After looking at the log in more detail, I can see where the unwanted "\" is being added during the "CostFinalise" action:

Code: Select all

MSI (c) (B8:A0) [08:40:32:488]: Doing action: CostFinalize
Action 08:40:32: CostFinalize. Computing space requirements
Action start 08:40:32: CostFinalize.
...
MSI (c) (B8:A0) [08:40:32:754]: PROPERTY CHANGE: Modifying SOURCEDIRBACKUP property. Its current value is 'C:\p4_PI-1091666_PI-126\AllDay\src_MSVS2K8\build\Backup\Test.bak'. Its new value: 'C:\p4_PI-1091666_PI-126\AllDay\src_MSVS2K8\build\Backup\Test.bak\'.
...
Action ended 08:40:33: CostFinalize. Return value 1.
Is there a way to stop this from happening, or do I need to parse the unwanted character out before I use the value?
mihai.petcu
Posts: 3860
Joined: Thu Aug 05, 2010 8:01 am

Re: BrowseForFile doesn't display dialog

Hello Ash and welcome to the Advanced Installer Forums,
Is there a way to stop this from happening, or do I need to parse the unwanted character out before I use the value?
This is happening probably because during "CostFinalize" Windows Installer interprets your property as being a directory path and not a file path. Thus it validates it by appending the backslash at the end.
If the file specified in the 'AI_OFN_FILEPATH' property does not exist, the Browse dialog is not displayed. Once I click the Browse button, how can I validate whether the file exists and if it doesn't, use the "[SETUPEXEDIR]" folder (without a "\") instead?
You can add a search for your file from the "Search" page and then use this tutorial to conditionally display the browse dialog. This article from our user guide can show you how to set the [SETUPEXEDIR] property.
Please also set the event's condition to:

Code: Select all

NOT MY_SEARCH_RESULT
where MY_SEARCH_RESULT is the name of your search.

Regards,
Mihai
Mihai Petcu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
ash_microsec
Posts: 38
Joined: Thu Dec 16, 2010 9:35 am
Location: Emsworth

Re: BrowseForFile doesn't display dialog

Thanks for your reply, Mihai. Unfortunately I am still not sure how your reply helps in my circumstances, so let me elaborate.

The dialog is displayed as part of the "InstallMode=InstallModeCustom" dialog sequence. I have a default value (in an Install Parameter) which is the name of a file which MAY (or may not) exist in the "[SETUPEXEDIR]\Backup" folder. The dialog displays a read only text box (which displays the property's value), a Browse button, and a Next button.

Questions:
1. When the dialog is displayed, how do I disable the "Next" button if the default file (e.g. "[SETUPEXEDIR]\Backup\Test.bak") does not exist?

2. If the default file does not exist and the user clicks the Browse button, how do I get the Browse dialog to display the folder "[SETUPEXEDIR]" ?

2. When the Browse button is used to specify a different file, the property is updated. How do I then reenable the "Next" button when the file exists?

3. How do I ensure the file name put into the property does NOT have an unwanted "\" at the end of the string?

Thanks.
mihai.petcu
Posts: 3860
Joined: Thu Aug 05, 2010 8:01 am

Re: BrowseForFile doesn't display dialog

Hello,
When the dialog is displayed, how do I disable the "Next" button if the default file (e.g. "[SETUPEXEDIR]\Backup\Test.bak") does not exist?
You can add a search for that file in the "Search" page and then use the name of the search to condition the "Next" button from the "Control Conditions" tab in the "Dialogs" page. The "Action" should be "Disable" and the condition should look something like:

Code: Select all

NOT MY_SEARCH
where MY_SEARCH is the name of the search.
If the default file does not exist and the user clicks the Browse button, how do I get the Browse dialog to display the folder "[SETUPEXEDIR]" ?
You can add a "SetProperty" event on the "Browse" button:
Name:[AI_OFN_FILEPATH]
Argument:[SETUPEXEDIR]
Condition:NOT MY_SEARCH
where MY_SEARCH is the name of the search from the first question.
When the Browse button is used to specify a different file, the property is updated. How do I then reenable the "Next" button when the file exists?
Add another control condition to the "Next" button, similar to the one from the first question. The action should be "Enable" and the condition should be:

Code: Select all

MY_SEARCH
How do I ensure the file name put into the property does NOT have an unwanted "\" at the end of the string?
You can follow our FAQ regarding this and also investigate the possible reason I mentioned in my previous post.

Regards,
Mihai
Mihai Petcu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
ash_microsec
Posts: 38
Joined: Thu Dec 16, 2010 9:35 am
Location: Emsworth

Re: BrowseForFile doesn't display dialog

Thanks for your reply. I have followed the first part of your instructions; the File Search, the condition on the Browse button, and the control condition on the Next button. What I now get is:
  • My Install Parameter "BACKUPFILE" has a default value of "[SETUPDIREXE]Backup\Test.bak" and this is happily resolved when the installer package starts.
  • A File Search "BACKUPFILE_EXISTS" with the property Name of "[SETUPDIREXE]Backup\Test.bak".
  • A dialog with the Next button disabled because "BACKUPFILE_EXISTS" indicates that the backup file doesn't exist, then,
  • the Browse dialog displays the "[SETUPEXEDIR]" folder (NOTE - the "[AI_OFN_FILEPATH]" argument has to include the file name "[SETUPEXEDIR]Test.bak" for the browse dialog to be displayed).
  • When the user selects a BAK file, the "BACKUPFILE" install parameter is updated with the name of the selected file.
However, the Next button does NOT become enabled because I get an error if I try to create a File Search using the property Name of "[|BACKUPFILE]" - the error message is "Exception - The property value '[SETUPEXEDIR]Backup\Test.bak' is disallowed in FileSearchSign_1.", then the property value is replaced with "[SETUPDIREXE]Backup\Test.bak". It appears I cannot use a parameter which includes a parameter?

I need the Next button's enable condition to check the file specified in the "BACKUPFILE" parameter exists. How should I do this if I cannot create a File Search for the parameter "[BACKUPFILE]"?
ash_microsec
Posts: 38
Joined: Thu Dec 16, 2010 9:35 am
Location: Emsworth

Re: BrowseForFile doesn't display dialog

ash_microsec wrote:I need the Next button's enable condition to check the file specified in the "BACKUPFILE" parameter exists. How should I do this if I cannot create a File Search for the parameter "[BACKUPFILE]"?
Ok, this is a hack, but I have a workaround by adding an additional event to the Browse button's Published Events:
  • 1. "[AI_OFN_FILE_PATH]" is set.
    2. The "DoAction" event calls the "BrowseForFile" custom action to display the Browse dialog.
    3. The "BACKUPFILE" parameter is set with the "[AI_OFN_FILEPATH]" value IF the "AI_OFN_FILEPATH" condition (is not empty) is true.
    4. NEW - The search parameter "BACKUPFILE_EXISTS" parameter is set with "1" IF the "AI_OFN_FILEPATH" condition (is not empty) is true.
When the "BACKUPFILE_EXISTS" value is manually changed, this is detected by the Next button's control condition and the Next button becomes enabled.

Return to “Common Problems”