467,169 Members | 946 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,169 developers. It's quick & easy.

How to set value of <INPUT type=file...> element programmatically?

Hi ALL.

I need to simulate send POST data ( - file upload) as it was submitted in Browser. In C# I create instanse of IE, navigate to page with the form, fill in the fields and try to Submit by call submitButton.click() Unfortunately it does not work while file_filed.vale = <path_to_file> has no effect, value <INPUT type=file...> cound not be set from script of that HTML page. Is there another way to set that value by means of ..NET ? Below the part of code :

SHDocVw.InternetExplorer ie = new SHDocVw.InternetExplorerClass();
object o = null;
ie.Navigate( url, ref o, ref o, ref o, ref o ); // navigate to page with the form and waiting for DownloadComplete
..............................................
mshtml.HTMLDocument doc = (mshtml.HTMLDocument)ie.Document;
mshtml.IHTMLInputFileElement file = (mshtml.IHTMLInputFileElement)doc.getElementsByNam e("file").item(null,0);
file.value = m_sPathToFile; // has no effect!!!!!!!
mshtml.HTMLInputButtonElement btn = (mshtml.HTMLInputButtonElement)doc.getElementsByNa me("send").item(null,0);
btn.click();

.........................

Thank you for any help

Evgeny

Nov 16 '05 #1
  • viewed: 26603
Share:
2 Replies
"Evgeny Zoldin" <zo****@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl
I need to simulate send POST data ( - file upload) as it was
submitted in Browser. In C# I create instanse of IE, navigate to page
with the form, fill in the fields and try to Submit by call
submitButton.click() Unfortunately it does not work while
file_filed.vale = <path_to_file> has no effect, value <INPUT
type=file...> cound not be set from script of that HTML page. Is
there another way to set that value by means of .NET ?


There is no way to set the value programmatically, with .NET or
otherwise, for security reasons. value property on <input type="file">
element is read-only.
--
With best wishes,
Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken
Nov 16 '05 #2
Hi,
It can't be done programmatically; user has to manually select the file for
uploading.

"Evgeny Zoldin" <zo****@hotmail.com> wrote in message
news:#v**************@TK2MSFTNGP09.phx.gbl...
Hi ALL.

I need to simulate send POST data ( - file upload) as it was submitted in
Browser. In C# I create instanse of IE, navigate to page with the form, fill
in the fields and try to Submit by call submitButton.click() Unfortunately
it does not work while file_filed.vale = <path_to_file> has no effect, value
<INPUT type=file...> cound not be set from script of that HTML page. Is
there another way to set that value by means of .NET ? Below the part of
code :

SHDocVw.InternetExplorer ie = new SHDocVw.InternetExplorerClass();
object o = null;
ie.Navigate( url, ref o, ref o, ref o, ref o ); // navigate to page with the
form and waiting for DownloadComplete

..............................................

mshtml.HTMLDocument doc = (mshtml.HTMLDocument)ie.Document;
mshtml.IHTMLInputFileElement file =
(mshtml.IHTMLInputFileElement)doc.getElementsByNam e("file").item(null,0);
file.value = m_sPathToFile; // has no effect!!!!!!!
mshtml.HTMLInputButtonElement btn =
(mshtml.HTMLInputButtonElement)doc.getElementsByNa me("send").item(null,0);
btn.click();
.........................

Thank you for any help
Evgeny
Nov 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Martin Lucas-Smith | last post: by
2 posts views Thread by not 2 swift | last post: by
3 posts views Thread by iinet | last post: by
10 posts views Thread by Brian Henry | last post: by
1 post views Thread by test9991014@yahoo.com | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.