|
-
Jun 17th, 2010, 06:22 PM
#1
Thread Starter
Addicted Member
[RESOLVED] UpLoadFile With WebBrowser
How I can Upload File with WebBrowser??
Y have a inputBox and a Button in a website and i if I press the button opens a CommonDialog me to scan the file and put the route on the input ...
this has to be very easy
Thanks
Last edited by *PsyKE1*; Jun 18th, 2010 at 08:39 AM.
-
Jun 17th, 2010, 09:33 PM
#2
Hyperactive Member
Re: UpLoadFile With WebBrowser
Use the PostData Parameter.
It's simple AND elegant
From THE MSDN
Code:
Sub Command1_Click()
Dim URL As String
Dim Flags As Long
Dim TargetFrame As String
Dim PostData() As Byte
Dim Headers As String
URL = "http://YourServer" ' A URL that will accept a POST
Flags = 0
TargetFrame = ""
PostData = "Information sent to host"
' VB creates a Unicode string by default so we need to
' convert it back to Single byte character set.
PostData = StrConv(PostData, vbFromUnicode)
Headers = ""
WebBrowser1.Navigate URL, Flags, TargetFrame, PostData, Headers
End Sub
Hope this helps
-
Jun 18th, 2010, 02:19 AM
#3
Thread Starter
Addicted Member
Re: UpLoadFile With WebBrowser
mmmm
Thanks but I've been looking and can not find what I wanted ... 
This is the code of the web with the need to interact:
Code:
<input type="file" name="archivo" id="idarchivo">
<br>
<br>
<input type="submit" name="enviar" value="Submit-enviar" onclick="alert('ok1')">
<br>
<br>
Y use this but it doesn't works:
Code:
WebBrowser1.Document.All("archivo").Value = "C:\File.txt"
WebBrowser1.Document.All("enviar").Click
What am I doing wrong? 
Thanks!
-
Jun 18th, 2010, 06:05 AM
#4
Lively Member
Re: UpLoadFile With WebBrowser
 Originally Posted by *PsyKE1*
mmmm
Thanks but I've been looking and can not find what I wanted ... 
This is the code of the web with the need to interact:
Code:
<input type="file" name="archivo" id="idarchivo">
<br>
<br>
<input type="submit" name="enviar" value="Submit-enviar" onclick="alert('ok1')">
<br>
<br>
Y use this but it doesn't works:
Code:
WebBrowser1.Document.All("archivo").Value = "C:\File.txt"
WebBrowser1.Document.All("enviar").Click
What am I doing wrong?
Thanks! 
Yep that will not work instead you can use the sendkeys function
vb Code:
wb1.Document.All.Item("archivo").Focus
SendKeys "C:\test.txt"
Something like that
-
Jun 18th, 2010, 06:15 AM
#5
Re: UpLoadFile With WebBrowser
afaik you can not automate a file input
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Jun 18th, 2010, 07:32 AM
#6
Thread Starter
Addicted Member
-
Jun 18th, 2010, 08:22 AM
#7
Lively Member
Re: UpLoadFile With WebBrowser
 Originally Posted by *PsyKE1*
@_-Rs-_
It works!! 
Thanks, but are you sure it's the best way to do it?? 
So I can't do otherwise than with SendKeys?
Thanks again 
Well bro it's true SendKeys has lot of issues may not be reliable at all
But it's up to you what functions or controls you prefer to use 
But there are other ways to do this aswell like using winsock , Inet ect..
Or using other VB functions 
EDIT: Dont forget to mark the thread as SOLVED if you found what your looking for
Last edited by _-Rs-_; Jun 18th, 2010 at 08:31 AM.
-
Jun 18th, 2010, 08:38 AM
#8
Thread Starter
Addicted Member
Re: UpLoadFile With WebBrowser
Thanks! 
RESOLVED
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|