Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - write into an <input type=file> field

Reply
 
Old 03-04-2009   #1 (permalink)
Reventlov


 
 

write into an <input type=file> field

Hello,
There is a page on the web with an input type=file field named "sourcefile".
While I can fill in the other fields in the form, nothing is written using
..document.forms(0).Item("sourcefile").value = "C:\Users\standard\Desktop\fax.doc"
The only way is to use sendkeys.

The fact is that if I manually select a file and then READ the value, it is correctly
retrieved.
msgbox .document.forms(0).item("sourcefile").value
returns the name of the file selected.

I can set the content of the field with a script in a local html file, but it seems not to
work (nothing is written to the field) in a vbs which loads the page and fills the form.

Being able to read the content, I am sure the path to the field is correct.

Thank you for your help.
Giovanni.

--
Giovanni Cenati (Bergamo, Italy)
Write to "Reventlov" at katamail com
http://digilander.libero.it/Cenati (Esempi e programmi in VbScript)
--

My System SpecsSystem Spec
Old 03-04-2009   #2 (permalink)
Paul Randall


 
 

Re: write into an <input type=file> field


"Reventlov" <noone@xxxxxx> wrote in message
news:49acec72.56705734@xxxxxx
Quote:

> Hello,
> There is a page on the web with an input type=file field named
> "sourcefile".
> While I can fill in the other fields in the form, nothing is written using
> .document.forms(0).Item("sourcefile").value =
> "C:\Users\standard\Desktop\fax.doc"
> The only way is to use sendkeys.
>
> The fact is that if I manually select a file and then READ the value, it
> is correctly
> retrieved.
> msgbox .document.forms(0).item("sourcefile").value
> returns the name of the file selected.
>
> I can set the content of the field with a script in a local html file, but
> it seems not to
> work (nothing is written to the field) in a vbs which loads the page and
> fills the form.
>
> Being able to read the content, I am sure the path to the field is
> correct.
>
> Thank you for your help.
> Giovanni.
Can you build a little HTA that contains the relevant code and demonstrates
how it does or doesn't work, and post it here?

-Paul Randall


My System SpecsSystem Spec
Old 03-04-2009   #3 (permalink)
T Lavedas


 
 

Re: write into an <input type=file> field

On Mar 4, 3:38*pm, no...@xxxxxx (Reventlov) wrote:
Quote:

> Hello,
> There is a page on the web with an input type=file field named "sourcefile".
> While I can fill in the other fields in the form, nothing is written using
> .document.forms(0).Item("sourcefile").value = *"C:\Users\standard\Desktop\fax.doc"
> The only way is to use sendkeys.
>
> The fact is that if I manually select a file and then READ the value, it is correctly
> retrieved.
> msgbox .document.forms(0).item("sourcefile").value
> returns the name of the file selected.
>
> I can set the content of the field with a script in a local html file, but it seems not to
> work (nothing is written to the field) in a vbs which loads the page and fills the form.
>
> Being able to read the content, I am sure the path to the field is correct.
>
> Thank you for your help.
> Giovanni.
>
> --
> Giovanni Cenati (Bergamo, Italy)
> Write to "Reventlov" at katamail comhttp://digilander.libero.it/Cenati(Esempi e programmi in VbScript)
> --
This is the intended behavior of the FILE type of the INPUT element.
Otherwise, permitting a default value to be defined would open a
security hole. That is, a web page author could preload the INPUT
element value with file names and upload them to his/her server
without requiring the client's interaction. Not a good thing.

The use of Sendkeys is the only known way to populate a file type
input box (in a client initiated script application). That's why I
worked to find a way to use drag-and-drop onto IFRAMEs in HTAs. It
greatly simplifies the loading of files.

Tom Lavedas
***********
http://there.is.no.more/tglbatch/
My System SpecsSystem Spec
Old 03-10-2009   #4 (permalink)
Reventlov


 
 

Re: write into an <input type=file> field

Il giorno Wed, 4 Mar 2009 13:40:39 -0800 (PST), T Lavedas <tglbatch@xxxxxx> ha scritto:
Quote:
Quote:

>> There is a page on the web with an input type=3Dfile field named "sourcef=
>ile".
Quote:

>> While I can fill in the other fields in the form, nothing is written usin=
>g
Quote:

>> .document.forms(0).Item("sourcefile").value =3D =A0"C:\Users\standard\Des=
>ktop\fax.doc"
Quote:

>> The only way is to use sendkeys.
Quote:

>This is the intended behavior of the FILE type of the INPUT element.
>Otherwise, permitting a default value to be defined would open a
>security hole. That is, a web page author could preload the INPUT
>element value with file names and upload them to his/her server
>without requiring the client's interaction. Not a good thing.
>
>The use of Sendkeys is the only known way to populate a file type
>input box (in a client initiated script application). That's why I
>worked to find a way to use drag-and-drop onto IFRAMEs in HTAs. It
>greatly simplifies the loading of files.
Thank you very much.
It is important to know there is a reason for this behaviour.


--
Giovanni Cenati (Bergamo, Italy)
Write to "Reventlov" at katamail com
http://digilander.libero.it/Cenati (Esempi e programmi in VbScript)
--
My System SpecsSystem Spec
Old 03-10-2009   #5 (permalink)
Reventlov


 
 

Re: write into an <input type=file> field

Il giorno Wed, 4 Mar 2009 14:20:57 -0700, "Paul Randall" <paulr90@xxxxxx> ha scritto:
Quote:

>Can you build a little HTA that contains the relevant code and demonstrates
>how it does or doesn't work, and post it here?
Sure,
it might be of help for those who want to automate interaction with a web site.

WScript.CreateObject("InternetExplorer.Application", "oIE_")
' Setta le proprietà della finestra del browser
oIE.left = 20 ' La finestra
oIE.top = 50 ' in alto a sinistra,
oIE.height = 380 ' piccola...
oIE.width = 580
oIE.menubar = 0 ' Senza menu
oIE.toolbar = 0 ' né barra degli strumenti
oIE.statusbar = 0 ' né barra di stato per essere più riconoscibile.
oIE.navigate("about:blank") ' Crea un documento HTML vuoto.
oIE.visible = 1


homepage="http://corrisp/dsp.asp?pagenumber=1"

oIE.navigate(homepage) 'Richiede la pagina
Do until oIE.readystate = 4 : wscript.sleep 10: Loop

oie.Document.Forms(0).item("nr").Value = "1368223"
oie.Document.Forms(0).item("dt").Value = "2008"
oIE.Document.forms(0).submit

but

oie.document.forms(0).item("file").value ="c:\data.txt"

doesn't fill the field.
--
Giovanni Cenati (Bergamo, Italy)
Write to "Reventlov" at katamail com
http://digilander.libero.it/Cenati (Esempi e programmi in VbScript)
--
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
how to get powershell to write to event log or write a log file? PowerShell
doesn't display me to write Filename and file type General Discussion
VbSystemModal type functionality for Read-Host input PowerShell
Input Type Hidden and Checkbox? VB Script
Don't write your Password in the User field on a fresh Vista insta Vista account administration


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46