开发者

C#: How to set the value of an mshtml.HTMLInputFileElement

开发者 https://www.devze.com 2023-01-09 00:02 出处:网络
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 diffic

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消