Auto fill form?

Add-in Express™ Support Service
That's what is more important than anything else

Auto fill form?
 
Erick Stover




Posts: 4
Joined: 2010-10-21
I just got this project dumped on me (old developer quit a week before project was due and hadn't actually worked on the project at all). I've been a web developer (asp.net) for a while but desktop development is relatively new to me.

Here is the situation I have:

There is a web page with three fields that needs to be filled with values from their local computer. I already have the ability to grab the values working. No worries there. The problem is autofilling those fields (field names: txtCat, txtMod, txtNum). The way I would normally parse through a series of controls on a page apparently isn't working in this context. Can someone at least point me in the right direction to fill those fields?

Thanks!
Posted 21 Oct, 2010 09:45:40 Top
Andrei Smolin


Add-in Express team


Posts: 14372
Joined: 2006-05-11
Hi Erick,

Can you please provide more details? If that was not a pure asp.net question, we will try to help.

Regards from Belarus (GMT+2),

Andrei Smolin
Add-in Express Team Leader
Posted 22 Oct, 2010 05:55:16 Top
Erick Stover




Posts: 4
Joined: 2010-10-21
no no, this was a purely Add-in Express related question. From a Internet Explorer Toolbar created with your plugin, how would I go about inserting a value into a form field on a page the user is at?

Say the value "steve" going into an input field with the id of "txtName".

In normal vb.net I know it would just be a matter of txtName.text = "steve" or looping through the controls to find "txtName" but I'm not sure how to actually access the displayed page/form from a created Add-in toolbar. That's the part that's not clicking with my brain.
Posted 22 Oct, 2010 09:05:57 Top
Andrei Smolin


Add-in Express team


Posts: 14372
Joined: 2006-05-11
Hi Erick,

You can access the currently displayed page via the HTMLDocument property of the module. Probably, you'll need to set new values in the DownloadComplete, DocumentComplete or NavigateComplete2 event of the module.

Regards from Belarus (GMT+2),

Andrei Smolin
Add-in Express Team Leader
Posted 22 Oct, 2010 12:48:00 Top
Erick Stover




Posts: 4
Joined: 2010-10-21
Got it working! Turns out it was much simpler than I was thinking it would be. For any future visitors, here is the working code attached to a button:

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        While Me.HTMLDocument.readyState <> "complete"
            'wait
        End While
        If Me.HTMLDocument.url = "http://www.darkhorizon.org/rftest.html" Then


            Debug.WriteLine("outerHTML:" & Me.HTMLDocument.documentElement.outerHTML)

            Dim wbd As mshtml.HTMLInputElement

            For Each wbd In Me.HTMLDocument.getElementsByTagName("input")
                Debug.WriteLine("DocObj: " & wbd.name)
                Select Case wbd.name
                    Case "txtName"
                        wbd.value = "Mr. Crispy"
                    Case "txtNumber"
                        wbd.value = "904-867-5309"
                End Select
            Next
        End If
    End Sub
Posted 25 Oct, 2010 11:14:04 Top
Eugene Astafiev


Add-in Express team


Posts: 8540
Joined: 2007-07-25
Hi Erick,

Thank you for sharing your code for others! Good luck with your add-in project!
.NET, Extended MAPI, Windows Phone & RT
Posted 25 Oct, 2010 11:18:35 Top
Erick Stover




Posts: 4
Joined: 2010-10-21
No problem at all!

One more quick (I hope) question....

Given the code above, say those tags are in a frame. How would I modify the Me.HTMLDocument.getElementsByTagName("input") line to account for that?

UPDATE!
Nevermind, I figured it out.

I first had to figure out the frame index number of the form I needed (it was 1, easy enough) then I had to modify the code as follows:


        Dim wbd As mshtml.HTMLInputElement

        Dim f1 As mshtml.IHTMLWindow2 = CType(Me.HTMLDocument.frames.item(1), mshtml.IHTMLWindow2)
        Dim f2 As mshtml.HTMLDocument = CType(f1.document, mshtml.HTMLDocument)

        For Each wbd In f2.getElementsByTagName("input")
            Debug.WriteLine("DocObj: " & wbd.name)
            Select Case wbd.name 
                    Case "txtName" 
                        wbd.value = "Mr. Crispy" 
                    Case "txtNumber" 
                        wbd.value = "904-867-5309" 
                End Select 
        Next
Posted 25 Oct, 2010 15:17:02 Top
Eugene Astafiev


Add-in Express team


Posts: 8540
Joined: 2007-07-25
Hi Erick,

Good news! Thank you for letting me know.
.NET, Extended MAPI, Windows Phone & RT
Posted 26 Oct, 2010 03:33:34 Top