FileDialog

Introducing FileDialog

The FileDialog component provides the function to display the file selection dialog box when the user selects the file. The executable file dialog box displays the system-provided dialog box. The FileDialog component displays the dialog box and provides the filtering function to reduce the file selection range.

Range of Support

Since the FileDialog component is affected by the operating system and execution environment, the range of support for each property, method, and event may be different, and there may be differences for each parameter as well.


nexacro Browser

(desktop)

nexacro Browser

(mobile)

IE10, 11, Chrome, Firefox, Opera

Android, iOS default Web Browser

Edge, Safari

Property

accept

X

X

O

O

X

defaultextension

O

O

X

X

X

dialogtype

X

O

X

X

X

filter

O

O

X

X

X

filterindex

O

O

X

X

X

Method

open

O

O

O

O

O

Event

onclose

O

O

O

O

O

FileDialogEventInfo

path

O

O

X

X

X

reason

O

O

O

O

O

virtualfiles

O

O

O

O

O

Running FileDialog & Displaying Selected File

Run the file selection dialog box according to the option selected and display the selected file.

Example

Clicking the [open] button after selecting multiple files or filtering by file extension displays the file selection dialog box. When you select the file and close the file selection dialog box, the selected file name and size are displayed in the TextArea area.

sample_grid_26_01

sample_filedialog_01.xfdl

Core features used in the example

open

Displays the file selection dialog box. You can specify strTitle (file selection dialog box title) and constOpenMode (file selection option) as parameters. The strTitle parameter is not applied when running the web browser, and only 2 can be used for constOpenMode when running the web browser.

virtualfiles

If you close the file selection dialog box, the onclose event occurs, and you can check the selected file information in the virtualfiles property of the FileDialogEventInfo object. The virtualfiles property contains the VirtualFile object in the form of an array. You cannot directly create and use the VirtualFile object in the web browser environment.

accept

You can specify the file type in the form of the file extension or MIME type.

Please refer to the link below for the MIME type list.

https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Complete_list_of_MIME_types

How to implement an example

1

Place the Button component on the screen and place 2 Radio components below the Button component. Then, place the TextArea component that will display the list of selected files on the right.

2

Select FileDialog from the toolbar and add it to the screen. FileDialog is displayed in the Invisible Object area.

3

Edit innerdataset of the Radio component as follows. One specifies the constOpenMode parameter of the open method and the other specifies the accept property value.

4

Write the onitemchanged event function of the Radio component as follows. Set the item selected in the first Radio component as the parameter of the open method, and set the item selected in the second Radio component as the accept property value.

var constOpenMode = FileDialog.LOAD;

this.Radio00_onitemchanged = function(obj:nexacro.Radio,e:nexacro.ItemChangeEventInfo)
{
	if(e.postvalue==0)
	{
		constOpenMode = FileDialog.LOAD;
	}
	else
	{
		constOpenMode = FileDialog.MULTILOAD;
	}
};

this.Radio01_onitemchanged = function(obj:nexacro.Radio,e:nexacro.ItemChangeEventInfo)
{
	this.FileDialog00.set_accept(e.postvalue);
};

5

Write the onclick event function of the Button component as follows.

this.Button00_onclick = function(obj:nexacro.Button,e:nexacro.ClickEventInfo)
{
	this.FileDialog00.open('Nexacro N', constOpenMode);
};

6

Write the onclose event function of the FileDialog object as follows.

In the web browser, when the file selection dialog box is closed without selecting the file, the event does not occur. However, in the Nexacro browser, the event occurs; therefore you must process the exception. In the example below, no exceptions were processed.

this.FileDialog00_onclose = function(obj:nexacro.FileDialog,e:nexacro.FileDialogEventInfo)
{
	this.TextArea00.set_value("selectfiles: "+e.virtualfiles.length+"\n");
	for (var i = 0, len = e.virtualfiles.length, vFile; i < len; i++)
	{
		vFile = e.virtualfiles[i];
		vFile.addEventHandler("onsuccess", this.FileDialog_VirtualFile_onsuccess, this);
		
		vFile.open(null, VirtualFile.openRead);
	}
	
};

this.FileDialog_VirtualFile_onsuccess = function(obj:nexacro.VirtualFile, e:nexacro.VirtualFileEventInfo)
{
	switch (e.reason)
	{
		case 1:
			obj.getFileSize();
			break;
		case 9:
			this.TextArea00.set_value(this.TextArea00.value+obj.filename+"("+e.filesize+")\n");
			obj.close();
			break;
	}
}

When the onclose event occurs, you can check the selected file information in the virtualfiles property of the FileDialogEventInfo object. If only the file name is needed, then the filename property value is used. If the file size needs to be checked, then the getFileSize method is executed and the file size is checked within the onsuccess event function of the VirtualFile object.

To use the getFileSize method of the VirtualFile object, you must first execute the open method and register the onsuccess event. If the open method succeeds, then it then executes the getFileSize method.

The VirtualFile object obtained from the virtualfiles property of the FileDialogEventInfo object has limited functionality. When using the open method, the strFileName parameter cannot be specified, and only VirtualFile.openRead can be used for the constOptions parameter.

7

Run QuickView (Ctrl + F6) to check the result. Selecting the FileDialog.LOAD option allows you to select only one file, and selecting the FileDialog.MULTILOAD option allows you to select multiple files.