Tags: 304460a0, _nextpart_000_0012_01c484ae, charset, content-type, element, format, iso-8859-1, ltinput, message, mime, multi-part, net, plain, programmatically, sharp, text, typefilegt, value

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

On .Net » .Net C# (C sharp)

5,184 words with 2 Comments; publish: Mon, 02 Jun 2008 19:52:00 GMT; (100109.38, « »)

This is a multi-part message in MIME format.

--=_NextPart_000_0012_01C484AE.304460A0

Content-Type: text/plain;

charset="iso-8859-1"

Content-Transfer-Encoding: quoted-printable

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 =3D <path_to_file> = has no effect, value <INPUT type=3Dfile...> 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 =3D new SHDocVw.InternetExplorerClass();

object o =3D 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 =3D (mshtml.HTMLDocument)ie.Document;

mshtml.IHTMLInputFileElement file =3D = (mshtml.IHTMLInputFileElement)doc.getElementsByName("file").item(null,0);=

file.value =3D m_sPathToFile; // has no effect!!!!!!!

mshtml.HTMLInputButtonElement btn =3D = (mshtml.HTMLInputButtonElement)doc.getElementsByName("send").item(null,0)= ;

btn.click();

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

Thank you for any help

Evgeny

--=_NextPart_000_0012_01C484AE.304460A0

Content-Type: text/html;

charset="iso-8859-1"

Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

&

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 =3D has no effect, value = 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 =3D = new SHDocVw.InternetExplorerClass();object o =3D 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 =3D (mshtml.HTMLDocument)ie.Document;mshtml.IHTMLInputFileElement file =3D (mshtml.IHTMLInputFileElement)doc.getElementsByName("file").item(null,0);= file.value =3D m_sPathToFile; // has no effect!!!!!!!mshtml.HTMLInputButtonElement btn =3D (mshtml.HTMLInputButtonElement)doc.getElementsByName("send").item(null,0)= ;btn.click();

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

Thank you for any help

Evgeny

--=_NextPart_000_0012_01C484AE.304460A0--

All Comments

Leave a comment...

  • 2 Comments
    • "Evgeny Zoldin" <zoldin.net-csharp.todaysummary.com.hotmail.com> wrote in message

      news:%23vzad1JhEHA.3632.net-csharp.todaysummary.com.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

      #1; Mon, 02 Jun 2008 19:53:00 GMT
    • Hi,

      It can't be done programmatically; user has to manually select the file for

      uploading.

      "Evgeny Zoldin" <zoldin.net-csharp.todaysummary.com.hotmail.com> wrote in message

      news:#vzad1JhEHA.3632.net-csharp.todaysummary.com.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.getElementsByName("file").item(null,0);

      file.value = m_sPathToFile; // has no effect!!!!!!!

      mshtml.HTMLInputButtonElement btn =(mshtml.HTMLInputButtonElement)doc.getElementsByName("send").item(null,0);

      btn.click();

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

      Thank you for any help

      Evgeny

      #2; Mon, 02 Jun 2008 19:54:00 GMT