To make it come up in a dialog, I would recommend using a button in the dialog (I know you already know how to do that), and then use the on dialog event, something like this
set %file $$sfile($mircdir,*)
That will pop-up the select file dialog, when the button <ID> is pressed, and then the name of the selected file (with the full path) will be stored in the variable %file when the OK button is pressed. If the Cancel button is pressed, then %file will become $null (or empty).
Regarding the rest of your query, I am working on it, but it's taking longer than I thought it would. I will post the code here as soon as I can, but I don't want to give a time frame again, just in case.