Restricting file type in File Open Dialog of File Plugin

Hi all,

We will use the showFileOpenDialog() method to show up the FileDialog to choose the file to the user. Here, User can choose any file. But, Can we specify the file formats, so that user can choose only files of the specified file foramts(such as .jpg,.jpeg,.gif,.png etc.).

It is possible to specify a filter array, check the sample code of showFileOpenDialog():

// this selects only files '1', previous dir must be used 'null', no multiselect 'false' and
// the filter "JPG and GIF" should be used: 'new Array("JPG and GIF","jpg","gif")'
var file = plugins.file.showFileOpenDialog(1,null,false,new Array("JPG and GIF","jpg","gif"));

Hi Joas,

Thanks for the reply. But,
It isn’t working at my end…

var file = plugins.file.showFileOpenDialog(1,null,false,new Array("JPG and GIF","jpg","gif"));

:(

I didn’t noticed you are using Servoy 3.1. This feature was introduced in Servoy 3.5, you should consider upgrading if you want to use it.

Hmmm…

Is there any technique to get that in 3.1.

Thanks.

You could try use the file plugin that is shipping with Servoy 3.5 in your Servoy 3.1 installation, no guarantees but I think it should work ;)

Hi Nicola,

Thanks for your reply.

But, it is showing NoSuchMethodError, when i am using the file.jar file from the Servoy3.5. I think, it mayn’t supporting. :(

java.lang.NoSuchMethodError: com.servoy.j2db.util.FileChooserUtils.getAReadFile(Ljava/awt/Component;Ljava/io/File;I[Ljava/lang/String;)Ljava/io/File;
org.mozilla.javascript.JavaScriptException: java.lang.NoSuchMethodError: com.servoy.j2db.util.FileChooserUtils.getAReadFile(Ljava/awt/Component;Ljava/io/File;I[Ljava/lang/String;)Ljava/io/File;

It seems that if I provide a file type as filter, I see no directories anymore. So the filter also applies to folders and filters them away because they don’t match. Can this be fixed?