rsergeev
Posts: 3
Joined: Mon Mar 18, 2019 1:03 pm

SaveFileDialog on button click

Hi there!
Is it possible to show SaveFileDialog when user clicks on a button?
I created a custom action which prepares some data for saving in file. And I should allow user to select folder and file for saving prepared data. But it seems that installation process hangs in ShowDialog() method, but without showing any window. I use SaveFileDialog from System.Windows.Forms namespace. Any help will be appreciated.
Catalin
Posts: 6585
Joined: Wed Jun 13, 2018 7:49 am

Re: SaveFileDialog on button click

Hello Roman and welcome to Advanced Installer forums,

Yes, that is possible. I am not sure what kind of custom action you have created for this task, but here you can find a PowerShell script that calls the ShowDialog() method from within the [System.Windows.Forms] assembly:

Code: Select all

Add-Type -AssemblyName System.Windows.Forms

$string = 'Hello there, how are you?'
$saveDlg = New-Object -Typename System.Windows.Forms.SaveFileDialog
$saveDlg.ShowDialog()
$string | Out-File $saveDlg.FileName
This can be easily implemented in your project by following these steps:
  • go to "Custom Actions" and add a "PowerShellScriptInline" custom action without sequence. In order to add a custom action without sequence, simply press the "Add custom action without sequence" button which is placed to the right side of the custom action's name.
  • now please copy paste the above code under the "Your code goes here." comment.
  • the last thing that needs to be done is to show the dialog control (button) that will trigger this custom action. For instance, you can go to "Dialogs" page --> click on WelcomeDlg dialog --> click on the "Next" button --> under "Published Events" click "New..." in order to create an event as it follows:

    Event: Execute custom aciton
    Argument: PowerShellScriptInline
    Condition: leave default


    Now please schedule this event before the "Display a specific dialog" event. To do so, simply press on your event and then press the "Up" button which can be found on the right side.
Also, for your reference, please find attached to this thread a sample project I have created:

RomanSampleProject - SaveFileDlg.aip
(13.74 KiB) Downloaded 244 times

Hope this helps.

All the best,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
rsergeev
Posts: 3
Joined: Mon Mar 18, 2019 1:03 pm

Re: SaveFileDialog on button click

Thank you Catalin for your reply.
You solution works indeed:) and quite suitable for me. But I'm interested in why my solution doesn't work? I used 'Call function from attached native DLL' custom action written in c#. And it's possible to show message box or even create and run windows form application which shows a form, but this doesn't work with SaveFileDialog. I suppose that there is an issue with application context. But I'm not sure. Anyway thank you for working solution.
Catalin
Posts: 6585
Joined: Wed Jun 13, 2018 7:49 am

Re: SaveFileDialog on button click

Hello Roman,

You are always welcome. My pleasure to help.

In what regards the fact that your custom action was failing, I am not really sure why that happens. Have you followed our "How to create a fully fledged C# custom actions" aticle? Also, did you have a look on our "Call function from attached native DLL" article? If not, please do so, as I think you may find them useful.

All the best,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”