replacement VBscript code for "UserAccounts.CommonDialog" in HTA under Windows 7
-
Wednesday, April 06, 2011 3:01 PM
We have an HTA program which allows a user to browse their local filesystem, and select a file. It currently runs under Windows XP.
Unfortunately it appears that Microsoft has eliminated support for the object used to do the browsing (UserAccounts.CommonDialog) under Windows Vista & Windows 7.
If someone can point me to an example of the VBscript which can replace the "GetXMLFile" subroutine below, that would be most appreciated. (I really haven't done much scripting, and this legacy app has been dumped in my lap to get running under Windows 7.)
Here is HTA the program (pared down to the relevant code).
<head>
<HTA:APPLICATION
SCROLL="yes"
SINGLEINSTANCE="yes"
>
</head><script language="VBScript">
Sub GetXMLFile
Set commonDialog = CreateObject("UserAccounts.CommonDialog")
commonDialog.Filter = "Text Files|*.xml|All Files|*.*"
commonDialog.FilterIndex = 1
commonDialog.InitialDir = "c:\"
commonDialog.ShowOpen
xmlFileBox.value=commonDialog.FileNameEnd Sub
</script>
<body bgcolor="WhiteSmoke">
<br>
<div><label>XML File: </label><input type="text" size=40 value="" name="xmlFileBox"> <input type="button" style="width: 150px" value="Attach XML File" onClick="GetXMLFile"></div>
<br></body>
All Replies
-
Wednesday, April 06, 2011 5:30 PMModerator
-
Wednesday, April 06, 2011 5:35 PMModerator
This is about as close as I can figure ...
<head>
<HTA:APPLICATION
SCROLL="yes"
SINGLEINSTANCE="yes"
>
</head>
<script language="VBScript">
Sub Window_onload
" Preload starting folder location and file mask
GetxmlFile.focus
createobject("wscript.shell").sendkeys "C:\*.xml{enter}"
GetxmlFile.click ' optional
end sub
Sub GetxmlFile_onchange
xmlFileBox.value = GetxmlFile.value
End Sub
</script>
<body bgcolor="WhiteSmoke">
<br>
<div>
<label style='width:8%'>Get File: </label>
<input type=file size=40 name=GetxmlFile
title="Press Browse to select a file"><br>
<label style='width:8%'>XML File: </label>
<input type="text" size=40 value="" name="xmlFileBox">
</div>
<br>
</body>
Tom Lavedas- Edited by Tom LavedasModerator Wednesday, April 06, 2011 5:36 PM to fix the title
- Marked As Answer by TimothyDee Wednesday, April 06, 2011 9:19 PM
-
Wednesday, April 06, 2011 6:10 PMModerator
Hi Tom,
FYI, in IE8 and later, the file path text box for the <input type="file"> tag is read-only; see
http://blogs.msdn.com/b/ie/archive/2008/07/02/ie8-security-part-v-comprehensive-protection.aspx
(the info is in the section titled "File Upload Control")
HTH,
Bill
-
Wednesday, April 06, 2011 6:22 PMModeratorI guess I'll take the time to update to IE8 now ;^)
Tom Lavedas -
Wednesday, April 06, 2011 6:33 PMModeratorOK, I updated to IE8 and it did NOT change the performance of the HTA implementation. I could still poke the starting location and file mask into the dialog.
Tom Lavedas -
Wednesday, April 06, 2011 7:42 PMModerator
Good to know - I didn't test your code but I thought you might want to be aware of that limitation anyway.
Bill
-
Wednesday, April 06, 2011 9:12 PM
Thanks, Tom, this is exactly the type of example code I was looking for.
- Tim
-
Wednesday, April 06, 2011 9:27 PM
>>>FYI, in IE8 and later, the file path text box for the <input type="file"> tag is read-only;
I did notice different behavior trying set the input file path, however the difference seemed to be because of the OS, not IE.
I have IE8 on an XP machine and IE8 on a Windows 7.
On the XP machine, the HTA can set the default path of the input file.
On the Windows 7 machine, the first time the HTA was run, the path was set to my Desktop.
On subsequent runs of the HTA, it seems to be set to the directory last accessed by the HTA.
(At least that is what I think I am seeing...)
- Tim

