Solved

Visual studio 2005/2008 application

Posted on 2014-04-03
28
465 Views
Last Modified: 2014-04-21
Hi,

I need to access data from a text box or combo box from an open ASP.net application into a VB.Net application.

Please guide and provide resolution.
0
Comment
Question by:pranjal_ds
  • 14
  • 9
  • 2
  • +1
28 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39975466
Can you open the site within your application (using Webbrowser) or does it have to be opened in external browser?
0
 

Author Comment

by:pranjal_ds
ID: 39978162
Site is opened in Internet Explorer 6.0 version only.
0
 

Author Comment

by:pranjal_ds
ID: 39980920
Have you found any solution to my problem?
Please reply.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39982668
No. It would have been easier if the site could be opened within your application.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 39982946
If you are using Internet Explorer, there is the option of using IE Automation to enumerate all the open windows, and inspect that window to find what you are looking for.

InternetExplorer object
http://msdn.microsoft.com/en-us/library/aa752084(v=vs.85).aspx
0
 

Author Comment

by:pranjal_ds
ID: 39984980
Please give the code to open the site in my application. Then we can go further from this.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39985635
Add a webbrowser control on your form. Call its Navigate method with the URL.
0
 
LVL 25

Expert Comment

by:apeter
ID: 39985868
Use HMTLAgilityPack(http://htmlagilitypack.codeplex.com/) to open the site page in your vb.net application.  Parse the html which comes back to get the textbox/combo box value.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 39986133
Internet Explorer automation example:

' Add a COM reference to 'Microsoft Internet Controls' to the project. 
' Add a .NET reference to Microsoft.mshtml to the project. 

' NOTE: 
' Don't add an Imports mshtml if you want your Intellisense to work. 

Imports System.Collections.Generic
Imports SHDocVw

Public Class InternetExplorerWindows

	Public Shared Function GetWindows() As Dictionary(Of String, String)
		Dim list As New Dictionary(Of String, String)()
		For Each window As InternetExplorer In New ShellWindows()

			' Skip Windows Explorer instances, since the Document type is IShellFolderViewDual2. 
			If TypeOf window.Document Is mshtml.HTMLDocument Then
				list.Add(window.LocationURL, DirectCast(window.Document, mshtml.HTMLDocument).body.innerHTML)
			End If
		Next
		Return list
	End Function

	Public Shared Function GetIFrameHTML(frameID As String) As Dictionary(Of String, String)
		Dim list As New Dictionary(Of String, String)()
		For Each window As InternetExplorer In New ShellWindows()

			' Skip Windows Explorer instances, since the Document type is IShellFolderViewDual2. 
			If TypeOf window.Document Is mshtml.HTMLDocument Then
				Dim doc As mshtml.HTMLDocument = DirectCast(window.Document, mshtml.HTMLDocument)
				If doc.getElementById(frameID) IsNot Nothing Then
					Dim frame As mshtml.HTMLIFrame = DirectCast(doc.getElementById(frameID), mshtml.HTMLIFrame)
					Dim window2 As mshtml.HTMLWindow2 = DirectCast(frame.contentWindow, mshtml.HTMLWindow2)
					Dim windowDocument As mshtml.IHTMLDocument2 = DirectCast(window2.document, mshtml.IHTMLDocument2)
					list.Add(window.LocationName, windowDocument.body.outerHTML)
				End If
			End If
		Next
		Return list
	End Function

End Class

Open in new window

0
 

Author Comment

by:pranjal_ds
ID: 39986161
I have successfully opened a sample website in my Visual studio.net 2008 application which contains a textbox and dropdownlist.
Now how to access the contents from textbox or dropdownlist in my Visual studio.net 2008 application?

Please suggest.
0
 

Author Comment

by:pranjal_ds
ID: 39986202
What is SHDocVw?
And do I have to add the above code to a Module?
Then where do I have to call the functions defined?
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39986357
>I have successfully opened a sample website in my Visual studio.net 2008 application

Which of the above methods did you use?
0
 

Author Comment

by:pranjal_ds
ID: 39986464
Add a webbrowser control on your form. Call its Navigate method with the URL.  ------- given by CodeCruiser
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Author Comment

by:pranjal_ds
ID: 39986485
I have added a webbroser control to the form and then set the URL property to the website URL and it opened the website when I executed the project.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39988278
You can access an element in the site using following syntax

Msgbox WebBrowser1.Document.GetElementById("TextboxID").Value
0
 

Author Comment

by:pranjal_ds
ID: 39988617
Hi,

I have created 1 application in VB.Net as TestApp and 1 sample website and added 1 textbox and dropdownlist to the website, I have opened the website in Form1 and accessing data from Form2 using MsgBox(Form1.WebBrowser1.Document.GetElementById(TextBox1.Text))   as suggested by you but I am getting blank value.

Attached is the screenshot.

Please suggest.
SS1.JPG
0
 

Author Comment

by:pranjal_ds
ID: 39988687
If I use the way you gave I am getting error as in attached screenshot.
SS2.JPG
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39988997
You need to open your website and check its HTML source code to get the actual id of the HTML input control that your textbox gets rendered to and then use that ID in the line I provided.
0
 

Author Comment

by:pranjal_ds
ID: 39990847
Please guide how to view and get the HTML input control id from the HTML source code.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39991205
Right click in the browser and then click "View Source". Then read through the HTML to find the control. It will have a long name which will end in the name that you supplied to ASP.NET control.
0
 

Accepted Solution

by:
pranjal_ds earned 0 total points
ID: 39998924
I was able to get the value using below syntax:

MsgBox(Form1.WebBrowser1.Document.All("TBox1").GetAttribute("Value"))

Now I will try on the actual website and update you.
0
 

Author Comment

by:pranjal_ds
ID: 39999231
Hi,

Now I have a website opened in external application say App1 and I have created another application App2 and want to access the contents in Dropdown list currently active item from the website opened in App1.

Please suggest how this can be done.

Regards,
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39999445
Why do you want it across two apps? Why not access it in App1?
0
 

Author Comment

by:pranjal_ds
ID: 40000725
Because App1 is already coded by some other coder and I do not have access to his code.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 40004631
The comment that you have selected as the solution is not the solution so either select the correct solution or delete the question if it has not been answered.
0
 

Author Closing Comment

by:pranjal_ds
ID: 40012207
Solution given by CodeCruiser was correct, only a little bit difference in syntax.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Now-a-days, indirectly, postal services have been replaced by email services. Yes, whenever we hear the word "email" a lot of people only think of gmail. Some people still think that email and gmail are one and the same thing :-). Let's see some …
Internet is a big network which is formed by connecting multiple small networks.It is a platform for all the users which are connected to it.Internet act as platform in different fields. Such as: Internet  as a collaboration platform. Internet  as…
Google currently has a new report that is in beta and coming soon to Webmaster Tool accounts. This Micro Tutorial will highlight new features for Google Webmaster Tools.
This Micro Tutorial will demonstrate how to add subdomains to your content reports. This can be very importing in having a site with multiple subdomains.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now