Re: BrowseForFolder

From: Joe Earnest (joeearnestNO_at_SPAMqwest.netPLEASE)
Date: 03/30/04


Date: Tue, 30 Mar 2004 10:22:19 -0700

Hi,

"Rob Dowell" <tomthumbkop@yahoo.com> wrote in message
news:#0UJWFnFEHA.2976@TK2MSFTNGP10.phx.gbl...
>
> Thank you for your prompt reply. Further trial and error has shown me
> that indeed BrowseForFolder is completely useless on Windows XP when you
> want to select a file. It still works for folders just not for files. I
> suspect that it is due to some change in v6.0 of Shell32.dll.
>
> Have you heard of a solution or workaround for this?
>

Yes BrowseForFolder generates an untrappable error on any file selection in
WinXp and a for root file selection in Win2k. The root folder file issue
can be handled on older OS's. On WinXp, there are some CommonDialog based
objects that you can access. On all OS's there are the MS Java VM
CommonDialog based objects, but the MS Java VM is no longer loaded by
default on new installations of Win2k (SP4) and WinXp (SP1a). It is still
legally available as a freeware download from third-party sources. Finally,
the HTML Choose File browser can be pressed into service on any Windows OS
with IE 5+.

Here's some descriptions (these are not documented in MSDN). If you need
sample code, post back with which one you're interested in. Details and
sample code for the WinXp objects follows.

---
(1)  The MS Common Dialog Object (MSComDlg.CommonDialog)
The MSComDlg object is the best alternative, *if* you have a license for it
on all machines.  Otherwise it requires a large MS utility download.  It is
present on all installations and is exposed through the comdlg32.ocx file.
While this file is supplied with all versions of Windows, it requires a
license for scripting use, which is typically derived from the installation
of an MS development or programming application, such as VB or VideoStudio.
Fortunately, VBCCE, which MS provides as a free download, also installs a
license (credit Tom Lavedas).  VBCEE, unfortunately is a fairly large
installation (just to get
a license) and not appropriate for all users.  So most installations will
not have VBCCE or another development tool installed, and so will not have
access to the MSComDlg object dialogs.
MS - Visual Basic Control Creation Edition 5.0 (VBCCE)
http://download.microsoft.com/msdownload/sbn/vbcce/vb5ccein.exe
(2)  The Java File Objects (java:com.ms.wfc.ui.OpenFileDialog and
java:com.ms.wfc.ui.SaveFileDialog)
Prior to the MS settlement with Sun, versions of the MS CommonDialog class
file dialogs were available on all Windows installations with IE, through
the Java Virtual Machine objects, which were exposed through the msjava.dll
file, and which could be called from VBS through the MS Java VM.  After the
settlement, beginning in February 2003, new installations of Win2k
(essentially new SP4 installations) and WinXp (essentially new SP1a
installations) no longer implement the MS Java VM.  Prior versions of
Windows, and all versions of Win2k and WinXp installed prior to these SP
versions, regardless of whether they have been updated to current versions,
can still access these object dialogs through the MS Java VM.  (Credit
Alessandro Angeli MVP for the access method).
Here, it gets murky.  MS soon found that many older apps and websites rely
on MSJVM routines.  Problems with transitioning to the Sun Java VM resulted
in MS support of the MSJVM being extended through September 2004.  So some
new installations may still include the MSJVM.  In any event, prior versions
of Windows, and all versions of Win2k and WinXp installed (or compiled, for
CD versions) prior to the subject SP versions, regardless of whether they
have been updated to current versions, retain the MSJVM and can still access
these object dialogs.  (The MSJVM is not deleted by upgrades.)  MS
apparently previously licensed the MSJVM to third-party vendors and (as I
understand it) the licenses apparently continue to be valid under the
settlement.  So the installation file (msjavx86.exe - which is also included
as part of the WinXp SP1 package, but not the WinXp SP1a package) can be
legally downloaded for the indefinite future, free of charge from numerous
third-party sites, if not available on a particular installation.  Unlike
the MS CommonDialog VBCEE installation, this is not an overly large or
otherwise useless download, and may even be a wise precaution, as many older
applications appear to rely on routines in the MSJVM.  Here's MS info and
one third-party download source.
Transitioning from the Microsoft Java Virtual Machine
http://www.microsoft.com/mscorp/java/
MSJVM Transition FAQ
http://www.microsoft.com/mscorp/java/faq.asp
Frequently Asked Questions About the Microsoft VM and Windows 2000 Service
Pack 4 (MS Knowledge Base article 820101)
http://support.microsoft.com/default.aspx?scid=kb;EN-US;820101
Installations of Microsoft Virtual Machine
http://hp.vector.co.jp/authors/VA012735/vm_en.html
Discussions of the removal of the MS Java Virtual Machine (MSJVM),
transition, affected installations and alternatives, and one of many
third-party download sites for a legal, free download of msjavx86.exe, which
will install the MSJVM on new installations of Win2k and WinXp that lack
them. As with any third-party download, check the file for viruses.&nbsp;
Search for other current download sites using the filename as a search term.
(3)  The WinXp File Objects (UserAccounts.CommonDialog and
SAFRCFileDlg.FileSave)
These objects are available only on WinXp, and are exposed through the
nusrmgr.cpl control panel applet and safrcdlg.dll.  They are somewhat more
limited versions of the CommonDialog, but adequate.  The Open dialog is
almost complete, except for no retitling, no flag return and an archaic
multi-select function.  (Credit Alex Angelopoulos MVP for first posting
their existence.)
(4)  The Choose File HTML File Control Object
This is a Tom Lavedas-Walter Zachery workaround.  It runs a zero-sized IeApp
window with a file control, uses AppActivate and SendKeys to feed a default
value to the control, then clicks the control to open the HTML Choose File
box to select a single existing file.  Only selects existing files, has few
options, requires AppActivate and SendKeys (which can be problematic), and
has set file filtering for HTML-type files (though it pops up to *.* All
Files).  Although the least controlable, it does operate across all OS's,
and may be the only non-download solution for newer Win2k OS's.
---
---
The WinXp UserOpenDlg File Dialog
("UserAccounts.CommonDialog")
UserOpenDlg.fileName= string
UserOpenDlg.initialDir= string
UserOpenDlg.filter= string list
UserOpenDlg.filterIndex= integer
UserOpenDlg.flags= long integer
return= UserOpenDlg.showOpen
return= UserOpenDlg.fileName
Description
The UserOpenFileDlg object dialog is available in WinXp only, and is exposed
through the usrmgr.cpl control panel applet file.  It is somewhat limited in
comparison to either the MSComDlg Open dialog type or the MSOpenFileDlg
dialog, but has far more options than does the SAFRCFileOpenDlg dialog.  It
offers an adequate Open dialog alternative for WinXp use, particularly when
neither the MSComDlg nor the MSOpenFileDlg object is available, and when
multiple-file selection is not required.  It has no associated Save As
dialog component.  The UserOpenFileDlg dialog is much faster in operation
than either the MSComDlg object Open dialog or the JavaSaveDlg object
dialog, is user resizable, and will assume the WinXp theme or dialog style
setting.
The UserOpenFileDlg dialog is modal with a fixed Open dialog title.  It will
display a default file and open at a default folder.  It provides for full
CommonDialog file filtering and index options, and most CommonDialog
operational flags, although flag return is not implemented.  Its operation
is limited primarily with regard to retitling and multiple-file selections,
where the failure to implement an LFN null-character-delimited string list
return requires the use of an list-style dialog box, displaying and
returning files containing spaces as SFNs, and returning with the path and
selected files as a string list with space delimiters.
Methods and Properties
ShowOpen
Runs the file Open dialog and returns a result flag:
true (-1) The user selected or specified one or more files.
false (0) The user dismissed the dialog.
FileName
Specifies the initial single file name or mask ANSI text string in the File
name edit box.  If a file pathname is specified, this property also sets the
initial folder displayed, if the path exists, or displays the entire
pathname in the File name edit box, if it doesn't.  A file name or mask is
required to specify a default folder through this property.  Wildcards (*
and ?) are permitted in the file name or mask specification, regardless of
any optional character validation implementation, but other invalid file
name characters are only permitted if character validation is disabled.
Non-existent filenames and pathnames are displayed, regardless of any
optional existing file path or pathname requirement.  If omitted or
zero-length, the dialog displays an empty File name edit box.  If no path or
a non-existent path is specified, the dialog opens at the currently active
folder.
This property also returns any file selection or specification as an ANSI
text string.  For a single file, the LFN file pathname string is returned.
For a multiple-file selection or specification, the property returns a
string list of the file path and each filename selected, reduced to an SFN,
if it contains a space, and delimited by spaces.  If the dialog is
dismissed, any defined default string is returned, or a zero-length string
is returned, if there was no default specification.
InitialDir
Specifies an existing folder pathname ANSI text string for initial display.
This property allows specification of a default folder without a file name
or mask.  If omitted, zero-length or non-existent, the dialog opens at the
currently active folder.
Filter
Specifies a standard CommonDialog filter ANSI text string list of
alternating display text and file extension mask lists, delimited by pipe
( | ) characters.  If omitted or zero-length, the dialog displays an empty
Files of type box.  If omitted, zero-length or invalidly formatted as a text
message, a single-selection dialog will display all files, while a
multiple-selection dialog will display no files.
If a specific filter (e.g., *.txt) is implemented, then the first-listed
extension for the current filter will be added as an extension to any file
selected or specified that does not already have an extension matching one
of the listed extensions for the current filter.
FilterIndex
Specifies a 1-based positive integer index of the specified filter to
implement on dialog initiation.  If omitted or out-of-range, the first
listed filter, if any, is displayed and implemented on initiation.
Flags
The method accesses the standard CommonDialog long integer bitwise code
flags for dialog operation, but several of those flags are meaningless
because of the lack of a Flags property return.
&H0001 1 Sets (checks) the Read-only checkbox
&H0004 4 Hides the Read-only checkbox.
&H0008 8 Restores the prior current directory on exit.
&H0100 256 Allows user specification of invalid file name characters,
including wildcards (* and ?).  If not set, the dialog verifies valid file
name characters and recognizes wildcards as user-specified filtering for
selection.
&H0200 512 Allows multiple file selection in a fixed-size list-style dialog
box with all path and file names containing spaces reduced to SFNs, and
returns multiple selections via a string list delimited by spaces.
&H0800 2048 Requires a user-specified file path to exist.
&H1000 4096 Requires a user-specified file pathname to exist.
&H4000 16384 Allows the selection of files with sharing violations.
&H8000 32768 Suppresses return of files with read-only attributes set or
those in write-protected directories.
&H40000 262144 Uses all SFN file pathnames in a multiple-selection dialog
box.
&H100000 1048576 Cancels dereferencing of shell link files (including URLs).
Dereferencing calls any shell link selected.
---
' a single-selection Open dialog
set oDlg= createobject( _
  "userAccounts.commonDialog")
oDlg.flags= &h1804
oDlg.filter= "All Files|*.*|" _
  & "Text and Batch Files|*.txt;*.bat"
oDlg.filterIndex= 2
oDlg.initDir= "C:\"
qSln= oDlg.showOpen
select case (qSln)
  case true
    wscript.echo oDlg.fileName
  case false
    wscript.echo "Dialog cancelled."
end select
---
' a multiple-selection Open dialog
set oDlg= createobject( _
  "userAccounts.commonDialog")
oDlg.flags= &h1a04
oDlg.filter= "All Files|*.*|" _
  & "Text and Batch Files|*.txt;*.bat"
oDlg.filterIndex= 2
oDlg.initDir= "C:\"
qSln= oDlg.showOpen
select case (qSln)
  case true
    wscript.echo replace( _
      oDlg.fileName, " ", vbCr)
  case false
    wscript.echo "Dialog cancelled."
end select
---
---
The WinXp SafrcDlgs File Dialogs
("SAFRCFileDlg.fileSave")
SafrcSaveDlg.fileName= string
SafrcSaveDlg.fileType= string
return= SafrcSaveDlg.openFileSaveDlg
return= SafrcSaveDlg.fileName
Description
The SafrcDlgs are available in WinXp only, and are exposed through the
safrcdlg.dll file.  Both dialogs are quite limited in comparison to the
options available with the MSComDlg object dialogs, the JavaOpenDlg and
JavaSaveDlg object dialogs and the WinXp UserOpenDlg object dialogs.
Accordingly, there is little reason to use the SafrcOpenDlg object dialog.
The SafrcSaveDlg object dialog, however, offers a legitimate Save As dialog
for WinXp use, when the MSComDlg object is not licensed or the JavaSaveDlg
object is unavailable on new SP1a installations.  The SafrcFileSaveDlg
dialog is much faster in operation than is either the MSComDlg object Save
As dialog or the JavaSaveDlg object dialog, is user resizable, and will
assume the WinXp theme or dialog style setting.
The SafrcSaveDlg dialog is modal with a fixed Save As dialog title.  It will
display a default file or mask in the edit box, and open at the default file
pathname folder.  It displays all file types and will not provide a
meaningful file filter, but the Save as type box area can be used for a
short message.  It provides an overwrite prompt, but no file creation
prompt.  It allows user specification of non-existent files, but only with
an existing path, maintains the file selection folder as the active
directory on exit, validates file pathname characters, and does not
dereference shell link files.
Methods and Properties
OpenFileSaveDlg
Runs the file Save As dialog and returns a hard-typed long integer (vartype
19) result code:
1 The user selected or specified a file.
0 The user dismissed the dialog.
FileName
Specifies the initial single file name or mask ANSI text string in the File
name edit box.  If a file pathname is specified, this property also sets the
initial folder displayed, if the path exists, or displays the entire
pathname in the File name edit box, if it doesn't.  A file name or mask is
required to specify a default folder through this property.  Wildcards (*
and ?) are permitted in the file name or mask specification, but other
invalid file name characters are not permitted.  Non-existent filenames and
pathnames are displayed.  If omitted or zero-length, the dialog displays an
empty File name edit box.  If no path or a non-existent path is specified,
the dialog opens at the currently active folder.
This property also returns any LFN file pathname selection or specification
as an ANSI text string.  If the dialog is dismissed, any defined default
string is returned, or a zero-length string is returned, if there was no
default specification.
FileType
Specifies an ANSI text message string that appears in the Save as type box.
This property does not recognize the standard CommonDialog file filter
string list.  The string provided does not appear to have any operational
effect, but can serve as a short message.  If omitted, the dialog displays
an empty Save as type box.
---
set oDlg= createObject("safrcFileDlg.fileSave")
oDlg.fileName= "C:\*.*"
oDlg.fileType= "Any File Type"
qSln= cbool(oDlg.openFileSaveDlg)
select case qSln
   case true
      wscript.echo oDlg.fileName
   case false
      wscript.echo "Dialog cancelled."
end select
---
Joe Earnest
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.564 / Virus Database: 356 - Release Date: 01-19-04


Relevant Pages

  • Re: Exporting excel to text file
    ... filenumber is just a new local variable which is going to hold the system ... >> Thank you so much for your help, the While statement and empty is ... The selection may very large as compared to what is ... >> 'Walk down each row and include it in the string if the cell is not ...
    (microsoft.public.excel.misc)
  • Re: Query using 3 listboxes
    ... Dim MyDB As DAO.Database ... Dim strWhere As String ... Dim varItem As Variant ... MsgBox "Please make a selection from each list",, "Selection ...
    (microsoft.public.access.formscoding)
  • Boolean value stored in a combobox!
    ... I use the stored values in tblStorage to set some kind of default value next ... cboMemberCard instead of an empty string. ... selection. ... Dim db As Database, rst As Recordset ...
    (microsoft.public.access.formscoding)
  • Re: Exporting excel to text file
    ... >> Thank you so much for your help, the While statement and empty is ... The selection may very large as compared to what is ... >> Open Filename For Output As #filenumber ... >> 'Walk down each row and include it in the string if the cell is not ...
    (microsoft.public.excel.misc)
  • Re: Now were multibooting (was the Non Multibooters return)
    ... > primary active and only partition of the 1st HDD and lost with ... w9x installations MultiBooting? ... & do it after the other WinXP Installations have been Installed ... particularly the Boot Sector). ...
    (uk.people.silversurfers)