|
Util Object |
|
See Also: |
The Util.OpenFileDialog() method uses the standard Windows Open File Dialog to allow the user to select one or more paths.
VBScript:
JScript:
| Util | The Util object. |
| strStartPath | Optional. Start the Open File Dialog in this directory. If a filename is specified after the directory, then this file is the default selected file. If strStartPath is a relative path, then the path is resolved from the current directory. The default value is the current directory. |
| strFilterString | Optional. Specifies the types of files to be displayed. Use pairs of comma-separated values to allow multiple filters. Delimit multiple patterns with semicolons. The filter string syntax is: "Filter1Name,Filter1Pattern1;Filter1Pattern2 [,Filter2Name, Filter2Pattern...] " The default value is "All, *.*". |
| strTitle | Optional. A string to be displayed on the title bar of the Open File Dialog box. The default value is "Open". |
| flags | Optional. An ORed combination of OpenFileDialogFlags values.The default value is ofdFlagsNone. |
| varPaths | If ofdFlagAllowMultiSelect is included in the flags parameter, a SAFEARRAY of strings (paths) is returned. If the Cancel button was clicked, the SAFEARRAY is empty.If ofdFlagAllowMultiSelect is not specified, a string is returned. If the Cancel button was clicked, the string is empty. |
See the OpenFileDialogFlags Enum topic for values that can be used in the flags parameter.
As mentioned above, strStartPath may specify a file. In this case the filename is filled into the edit box when the Open File Dialog is opened. If a filename is not specified, (meaning you want the edit box to start out empty), then strStartPath must end with a '/' or '\'. If strStartPath does not end with a slash, then the last segment of the path is interpreted as a file.
Note: when using the ofdFlagAllowMultiSelect flag:
Dim rg
rg = Util.OpenFileDialog(..., ofdFlagAllowMultiSelect)
' IsArray(rg) will be True, since we used ofdFlagAllowMultiSelect
is the correct syntax, and
Dim rg(1)
rg = Util.OpenFileDialog(..., ofdFlagAllowMultiSelect)
will create a "type mismatch" error.
When using the ofdFlagAllowMultiSelect flag in JScript, the return value is a SAFEARRAY object, which JScript does not natively handle. Use JScript's VBArray object to access the SAFEARRAY.
This code snippet is taken from the SrcToHtml example, which ships with APGen. It allows the user to select one or more HTML, ASP, or APG files, and convert them so their source code is viewable in HTML.
<%#
' Array of file paths to convert
Dim rgInputFilePaths
' Check for input file
If (Script.Arguments.Count = 0) Then
' No arguments passed to this script,
' so prompt for files to be selected.
' Returns an Array
rgInputFilePaths = Util.OpenFileDialog("", _
"HTML type files,*.htm;*.html;*.asp;*.apg,All,*.*", _
"Select source file(s) to convert to HTML", _
ofdFlagFileMustExist Or ofdFlagAllowMultiSelect)
If (UBound(rgInputFilePaths) < 0) Then
' User clicked cancel (empty array)
Script.Abort
End If
Else
... ' Script arguments specify the files to be converted
#%>