<strong>Application</strong>: HTA (therefore IE) This is an application that uses SendKeys to populate a FILE input field.
<strong>Issue</strong>: File is never uploaded.
Does anyone know of what may be causing this and any workarounds?
<em>Sorry for lack of information. I will edit the question with additional information if no answers are submitted.</em>Answer1:
IE8 has set the <input type="file"> element to read-only in order to prevent security attacks. (see <a href="http://blogs.msdn.com/ie/archive/2008/07/02/ie8-security-part-v-comprehensive-protection.aspx" rel="nofollow">article</a>).
Therefore a programmatic way isn't possible.Answer2:
I actually solved this problem with an interesting trick. Here's how...
Create an external vbscript 'include file' called 'vbshelper.inc' which contains the following code:
function stuffKeys(x) Set wshShell = CreateObject("WScript.Shell") wshShell.Sendkeys(x) end function<hr />
Inside your HTML code header, place the following lines as your first < Script> element...
<Script language="VBScript" src="vbshelper.inc"> function defaultFldr() stuffKeys(" C:\Temp\*.txt~") end function function do_something() . . . etc end function </Script>
[Note-1 There is a space before the C in ' C:\Temp\*.txt~' and a tilde ( ~ ) after the .txt.]
[Note-2 I had to specify Script type=VBScript and not type="text/vbscript". I'm not sure why this is required.]<hr />
later, in your HTML code, create the button like this...
<input type="File" id="srcFile" onchange="do_something()" onclick="defaultFldr()">
[Note-3: I tried to call the stuffKeys function right from the onclick command, but it didn't work. Probably because you have to use single quotes around the folder string.]
So... You can't create the WScript object from within an HTML or HTA page, but it works when referenced from an external include file. Keep the 'vbshelper.inc' file in the same folder as your HTML or HTA file.Answer3:
Is it possible to use compatibility mode in IE8 as a work-around?