I am currently working on a project that needs to be able to set the value of an input element of type "file" in an HTML document using mshtml.HTMLInputFileElement. I am having a great deal of difficulty doing this.
First I tried this:
IHTMLInputFileElement element = (IHTMLInputFileElement)args[0];
string filename
element.value = newFileName;
But the value was not set. I then read on another forum that the value property could not be set directly, but could be set by giving the focus to that in开发者_如何学运维put element and then using SendKeys to send the value to the file element like so:
HTMLInputElement writableFileElement = (HTMLInputElement)element;
writableFileElement.focus();
SendKeys.SendWait(newFileName);
this also failed and threw a COM exception saying that the field was not writable.
Is there any way to set the value field of an HTMLInputFileElement?
No, search "browser file input stealing" in your favorite search engine for reasons.
The SendKeys hack was patched in IE8 and Firefox 2 I think.
精彩评论