Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to lauch "File dialog box" by vbscript?

108 views
Skip to first unread message

Tony Chung

unread,
Dec 12, 2003, 12:29:21 PM12/12/03
to
Hi all,

I am writting a web application program for internal
usage. One of the features is provide an GUI for entering
the local folder (not file) path. Does it possible:
1. Launch the OS file dialog box once user click on a
button -"browse"?
2. Retrieve the path of the selected folder in the file
dialog box if point 1 is possible.

Thanks for your kindly help,
Tony

Rob A.

unread,
Dec 13, 2003, 2:43:52 AM12/13/03
to
This will get you the 'Open File' dialog box.
I'll leave it to an ASP wiz to delve into how to use it in a web page
button.

========================================
Set strFile = CreateObject("UserAccounts.CommonDialog")
x = strFile.ShowOpen
WScript.Echo strFile.FileName
========================================

"Tony Chung" <anon...@discussions.microsoft.com> wrote in message
news:00d801c3c0d5$7a6f2fe0$a301...@phx.gbl...

Roland Hall

unread,
Dec 13, 2003, 6:11:51 AM12/13/03
to
"Tony Chung" wrote:
> I am writting a web application program for internal
> usage. One of the features is provide an GUI for entering
> the local folder (not file) path. Does it possible:
> 1. Launch the OS file dialog box once user click on a
> button -"browse"?
> 2. Retrieve the path of the selected folder in the file
> dialog box if point 1 is possible.

What is your application here and are you wanting to run this as an ASP file
or with CScript/WScript?

--
Roland

This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose.

Tony Chung

unread,
Dec 13, 2003, 9:51:22 AM12/13/03
to
My application will provide a flexible way to update the
modules of an appliance. My idea is that using a web page
with multiple check boxs. If a check box is checked, which
means this module should be upgraded; then clicking
the "submit" button will replace the existing files to
latest release.

I hope my application is running as a hta format.

Cheers,
Tony

>.
>

Tony

unread,
Dec 13, 2003, 10:09:17 AM12/13/03
to
Thanks for your reply.
But it does not work in my PC (win2k) :( . I just copy
your script belows to a vbs file, and run it by double
click it.

Here is WSH error prompt.
---------------------------
Windows Script Host
---------------------------
Script: G:\Documents and
Settings\Administrator\Desktop\a.vbs
Line: 1
Char: 1
Error: ActiveX component can't create
object: 'UserAccounts.CommonDialog'
Code: 800A01AD
Source: Microsoft VBScript runtime error

---------------------------
OK
---------------------------

>.
>

Joe Earnest

unread,
Dec 13, 2003, 11:20:44 AM12/13/03
to
Hi,

"Tony" <anon...@discussions.microsoft.com> wrote in message
news:07a301c3c18b$13b6ae20$a301...@phx.gbl...


| Thanks for your reply.
| But it does not work in my PC (win2k) :( . I just copy
| your script belows to a vbs file, and run it by double
| click it.

Unfortunately, the solution that Rob posted is WinXp-only. I don't know the
ASP implications, but the Common-Dialog file browsing common dialogs require
a bit of consideration in WSH-hosted vbs. Pick your poison:

The MS Common Dialog Object (MSComDlg.CommonDialog)

The MSComDlg object is the best alternative, 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). Most installations, however, will not have VBCCE or another
development tool installed, and so will not have access to the MSComDlg
object dialogs.

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 file objects, which were exposed through the msjava.dll file, and
which could be called from VBS through the MS Java VM. 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).

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.)

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, and has set file filtering for
HTML-type files (though it pops up to *.* All Files). The least
controlable, but operates across all OS's and may be the only solution for
newer Win2k OS's.

BrowseForFolder

Prior to Win2k, the Shell BrowseForFolder object could be used to select
files. That ability became problematic in Win2k and impossible in WinXp.
MS recommends that it not be used for file selection, though it's still
available for older OS's.

Many months ago, I posted a file dialog function that would test for all
four of the file dialog objects in order, to see what was available on a
particular computer, using a single set of options. Fairly complex, though.
Since then, I've improved it and limited to the three true Common-Dialog
pairs of objects, but I've also incorporated all my standard scripts into a
WSC file, with properties and methods and CHM file instructions, and they
are not be thoroughly error-tested since the conversion.

If you find one of the above that works on your system, I'll post back some
sample code and the MSDN references (if any).

Again, however, I have no idea how this translates into ASP availability.

Joe Earnest

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.521 / Virus Database: 319 - Release Date: 09-23-03


Joe Earnest

unread,
Dec 13, 2003, 11:46:36 AM12/13/03
to
oops, ...

The foregoing was a cut and paste from an earlier reply, and didn't include
an update on the MS Java VM option.

Prior to the MS settlement with Sun, these versions of the MS CommonDialog


class file dialogs were available on all Windows installations with IE,

through the MS Java Virtual Machine (MSJVM) msjava.dll file. Here it gets
murky. Beginning in February 2003, pursuant to the MS-Sun settlement
agreement, new installations of Win2k (essentially new SP4 installations)
and WinXp (essentially new SP1a installations) no longer implemented the
MSJVM. MS soon found, however, 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) 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.

mayayana

unread,
Dec 13, 2003, 11:54:06 AM12/13/03
to
Save the text below as an HTML or HTA file:

---------------------------------------------------------------

<HTML>
<HEAD>
<TITLE></TITLE></HEAD>
<BODY>

<SCRIPT LANGUAGE="VBScript">
Sub ButBrowse_onclick()
'-- show browse window and Get file path:
Dim sFile
sFile = Browse
If (sFile <> "") Then
'--Do something with file....
MsgBox sFile '--For demo
End If
End Sub


Function Browse()
Dim Q2, sRet, IE
On Error Resume Next
Q2 = chr(34)
Set IE = CreateObject("InternetExplorer.Application")
IE.visible = False
IE.Navigate("about:blank")
Do Until IE.ReadyState = 4
Loop

IE.Document.Write "<HTML><BODY><INPUT ID=" & Q2 & "Fil" & Q2 & "Type=" &
Q2 & "file" & Q2 & "></BODY></HTML>"
With IE.Document.all.Fil
.focus
.click
Browse = .value
End With
IE.Quit
Set IE = Nothing
End Function

</SCRIPT>

<INPUT NAME="ButBrowse" TYPE="button" TITLE="Browse to select file."
VALUE="Browse For File"></INPUT><BR>

</BODY></HTML>
--------------------------------------------------------

To get the folder path you can use this to snip off
file and backslash from path string::

i = instrrev(sFile, "\")
folderpath = left(sFile, (i - 1))

--
--
Tony Chung <anon...@discussions.microsoft.com> wrote in message
news:00d801c3c0d5$7a6f2fe0$a301...@phx.gbl...

0 new messages