CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 25

Thread: webbrowser

  1. #1
    Join Date
    May 2007
    Posts
    10

    webbrowser

    I'm trying to make a little app that will use the webbrowser to go to megaupload.com and upload a file

    but I'm having trouble filling out the form that has the file you upload, I think it's called uploadform.file.

    I can fill out other forms ok, for example the recipient's email form, I use WebBrowser1.Document.uploadform.toemail.Value = "email@email.com"
    but this same code isn't working for the file form

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    Re: webbrowser

    It works for me. Are you sure you are attempting to change it after the document has already completed loading?
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3
    Join Date
    May 2007
    Posts
    10

    Re: webbrowser

    yes I think so.. I can show you my code

    Private Sub Form_Load()
    WebBrowser1.Navigate "http://megaupload.com"
    End Sub

    Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
    If (pDisp Is WebBrowser1.Object) Then
    WebBrowser1.Document.uploadform.file.Value = "C:\test.txt"
    End If
    End Sub

  4. #4
    Join Date
    May 2002
    Posts
    10,943

    Re: webbrowser

    Well, in this scenario, you can't use WebBrowser1_DocumentComplete because that doesn't wait for embedded or onload objects. Megaupload.com is based on flash. That is an embedded object and therefore might not be loaded. To test my theory, I used the DocumentComplete and a standard button to call the changing of the text input. The DocumentComplete did not work, while I waited to see everything and the button did.

    Take a look here to see some solutions to this problem.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  5. #5
    Join Date
    May 2007
    Posts
    10

    Re: webbrowser

    I still can't fill out the form when the page is completely loaded, I waited for everything to load then used a button

    Private Sub Command1_Click()
    WebBrowser1.Document.uploadform.file.Value = "C:\test.txt"
    End Sub

    Can I see what code you used to fill out that form?

  6. #6
    Join Date
    Nov 2005
    Location
    Omaha, Nebraska, USA
    Posts
    696

    Re: webbrowser

    If you're trying to set the Value property of an HTMLInputElement with the TYPE attribute of FILE, you won't succeed.

    (e.g. the HTML tag looks similar to: <INPUT TYPE=FILE NAME="uploadfile"> )

    The HTMLInputElement's Value property is read only. It can only be assigned by the user bringing up the file selection dialog. From what I've heard, it's a security means to prevent people from creating hidden file upload objects on their forms for discreetly uploading files from your computer.
    Last edited by ChaosTheEternal; May 23rd, 2007 at 04:52 PM.

  7. #7
    Join Date
    May 2007
    Posts
    10

    Re: webbrowser

    Thanks, at least now I know what's wrong. So there isn't any workarounds for this problem? If not I guess winsock would be the only way to upload a file then right?

  8. #8
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: webbrowser

    Or create a batch file that will FTP it up.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  9. #9
    Join Date
    May 2002
    Posts
    10,943

    Re: webbrowser

    You could use click() to activate the open dialog window and then send keystrokes to specify the file's path.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  10. #10
    Join Date
    Nov 2005
    Location
    Omaha, Nebraska, USA
    Posts
    696

    Re: webbrowser

    Quote Originally Posted by PeejAvery
    You could use click() to activate the open dialog window and then send keystrokes to specify the file's path.
    Unfortunately, you can't. Using either the WebBrowser control or an IE object, if you programmatically click the "Browse" button, your program is blocked, waiting for the dialog to be dismissed.

    If you launch the Browse dialog from IE itself, it won't block your application and you could send the message to the browse dialog, but for full automation, you couldn't bring up the dialog and specify a file with one single-threaded VB application.

    EDIT: And I am wrong. It can be done.
    Last edited by ChaosTheEternal; May 25th, 2007 at 02:50 PM.

  11. #11
    Join Date
    May 2002
    Posts
    10,943

    Re: webbrowser

    Quote Originally Posted by ChaosTheEternal
    Unfortunately, you can't. Using either the WebBrowser control or an IE object, if you programmatically click the "Browse" button, your program is blocked, waiting for the dialog to be dismissed.
    I have done it before in older versions of Visual Basic. Hmmm. Maybe there was a trick to doing it. When I get to work, so I can use a PC (I'm a Mac user), I will open one of my older programs to see.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  12. #12
    Join Date
    May 2002
    Posts
    10,943

    Re: webbrowser

    Quote Originally Posted by PeejAvery
    When I get to work, so I can use a PC (I'm a Mac user), I will open one of my older programs to see.
    Update: WebBrowser1.Document.uploadform.file.Click works perfectly fine in older versions and in VB6.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  13. #13
    Join Date
    Nov 2005
    Location
    Omaha, Nebraska, USA
    Posts
    696

    Re: webbrowser

    Quote Originally Posted by PeejAvery
    Update: WebBrowser1.Document.uploadform.file.Click works perfectly fine in older versions and in VB6.
    In VB6, with a Reference to Microsoft Internet Controls (using IE7) and the following code:
    Code:
    Option Explicit
    
    Private WithEvents ie As InternetExplorer
    
    Private Sub Form_Load()
        Set ie = New InternetExplorer
        ie.Visible = True
        ie.Navigate "http://www.htmlcodetutorial.com/forms/_INPUT_TYPE_FILE.html"
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
        Set ie = Nothing
    End Sub
    
    Private Sub ie_DocumentComplete(ByVal pDisp As Object, URL As Variant)
        If ie.ReadyState = READYSTATE_COMPLETE Then
            ie.Document.Forms.Item(1).Children.Item(0).Click
            
            MsgBox "Tinker with it"
        End If
    End Sub
    The message box doesn't show up until the file browser dialog is dismissed.

    I can't test IE6, but I wouldn't expect it to react differently.

  14. #14
    Join Date
    May 2002
    Posts
    10,943

    Re: webbrowser

    So use a timer...

    Code:
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    
    Private Sub Form_Load()
        Timer1.Interval = 100
        Timer1.Enabled = True
        WebBrowser1.Visible = True
        WebBrowser1.Navigate "http://www.htmlcodetutorial.com/forms/_INPUT_TYPE_FILE.html"
    End Sub
    
    Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
        If WebBrowser1.ReadyState = READYSTATE_COMPLETE Then
            WebBrowser1.Document.Forms.Item(1).Children.Item(0).Click
        End If
    End Sub
    
    Private Sub Timer1_Timer()
      opendialog = FindWindow(vbNullString, "Choose file")
      If opendialog > 0 Then
        SendKeys "Tinker with it"
        Timer1.Enabled = False
      End If
    End Sub
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  15. #15
    Join Date
    Nov 2005
    Location
    Omaha, Nebraska, USA
    Posts
    696

    Re: webbrowser

    For some reason, I believed the Timer control in VB6 was tied to the UI thread and wouldn't trigger if it were blocked.

    I guess I'm wrong. And I'm glad to be proven wrong rather than falsely believe I was right.

    EDIT: Doesn't seem to work with an IE object, though. Works fine with a WebBrowser control.
    Last edited by ChaosTheEternal; May 25th, 2007 at 02:59 PM.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured