RE: UPLOADING ANY TYPE OF FILE AS ATTACHMENT IN EMAIL AND SEND THROUGH X++
FilenameOpen used to be used to get a file path, which is not what you need. You want to upload the whole file.
If simply using File::GetFileFromUser() doesn't work for you, either design a custom form or use a dialog. In either the case, the right control to use is FileUpload.
You seem to be trying to build a dialog at runtime, therefore you need code like this:
DialogGroup dialogGroup = dialog.addGroup("@SYS54759");
FormBuildControl groupControl = dialog.formBuildDesign().control(dialogGroup.name());
FileUploadBuild dialogFileUpload = groupControl.addControlEx(classstr(FileUpload), 'FileUpload');
dialogFileUpload.style(FileUploadStyle::MinimalWithFilename);
dialogFileUpload.baseFileUploadStrategyClassName(classstr(FileUploadTemporaryStorageStrategy));
Use Find references on FileUpload class to find concrete examples, including various ways how you can process the result.
If you need more specific advice, you'll have to tell us what exactly you're doing (e.g. maybe you want a SysOperation dialog).