472,145 Members | 1,396 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,145 software developers and data experts.

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
2 28056
"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
5 posts views Thread by Bart van Deenen | last post: by
1 post views Thread by test9991014 | last post: by
reply views Thread by Saiars | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.