ShowFileDialog()

Description

Show the system's save-file dialog or open-file dialog.

Syntax

ShowFileDialog(bSave, filter, filterIndex, defaultExtension, initialDir, allowMultiSelect, overwritePrompt, flags);

Parameters

bool bsave : true -- show save-file dialog, false -- show open-file dialog.
<string> filter :
the filter name specifies the filter pattern (for example, "JPG | *.jpg").
To specify multiple filter patterns, use a
semicolon to separate the patterns (for example, "JPG, PNG and TIF | *.jpg;*.png;*.tif"). A pattern
string can be a combination of valid file extensions with asterisk (*). Do not include spaces in the pattern string. To show all files,
use the string "All Files | *.*".
<int> filterIndex : determines the index for the filter string we set, in other words, where the filter string
should appear in the dialog's filters drop-down box. By default, it's 0 and you don't need to change it.
<string> defaultExtension : define the default extension which will be appended to the file name.
Only useful when you try to save an image or images.
If this member is NULL and the user fails to type an extension, no extension is appended.
<string> initialDir : the initial directory. The algorithm for selecting the initial directory varies on different platforms.
bool allowMultiSelect : true -- allow multiple selection, false -- only allow single file selection.
bool overwritePrompt : true -- if a file already exists with the same name, user needs to confirm before the existing file is overwritten,
false -- if a file already exists with the same name, it will be overwritten without further user confirmation.
<int> flags : if this parameter equals 0, the program will be initiated with the custom settings. Otherwise it will be initiated with default flags,
which means allowMultiSelect and overwritePrompt will not work.

Return value

bool

true indicates success. false indicates failure.

When 'false' is, check ErrorCode or ErrorString for error information.

Remarks

No matter it succeeded or failed, this method will trigger OnGetFilePath event. If more than one file are selected, the event will also be called multiple times.

See also

OnGetFilePath

Example

<input type="button" value="Load" onclick="LoadImage();" />	
			
<script>	
Dynamsoft.WebTwainEnv.RegisterEvent('OnWebTwainReady', Dynamsoft_OnReady); 	

var DWObject;

function Dynamsoft_OnReady() {
	DWObject = Dynamsoft.WebTwainEnv.GetWebTwain('dwtcontrolContainer'); 
	if (DWObject) {
		DWObject.RegisterEvent('OnGetFilePath', OnGetFilePath);
	}
}		
			
function LoadImage() {
	if (DWObject) {
		DWObject.IfShowFileDialog = false;
		DWObject.ShowFileDialog(false, "JPG, PNG , TIF | *.jpg;*.png;*.tif", 0, "", "", true, true, 0);
	}
}

function OnGetFilePath(bSave, filesCount, index, path, filename){
    if(bSave == false)
	{
		DWObject.LoadImage(path+'\\'+filename);
	}
}
</script>