I have a wpf application in that i have one text box in which i enter the url and i am fetching that web page in web browser control.Think general for example if i am opening any web page in web browser control in a wpf application i want fetch all the text from that web browser control and diplay it in a text box. from that text box i can export it into any file. i now need information on how to fetch all data from web browser control and then put it into a multi line text box.
Asked
Active
Viewed 3,687 times
1
-
Why not just use wdsl.exe? http://msdn.microsoft.com/en-us/library/7h3ystb6.aspx – paparazzo Jun 01 '12 at 12:06
-
No No.ok lets make this as general if i want to fetch any other web page data how to do that. i used web browser control . to open the web page but i am not able fetch the data from that control. – user1379584 Jun 01 '12 at 12:26
-
Where does "I need to fetch the data from that web service url which is shown on the browser and create a .wsdl file" fit in. – paparazzo Jun 01 '12 at 12:56
-
IHTMLDocument2 htmlDocument = webBrowser1.Document.DomDocument as IHTMLDocument2; IHTMLSelectionObject currentSelection= htmlDocument.selection; if (currentSelection!=null) { IHTMLTxtRange range= currentSelection.createRange() as IHTMLTxtRange; if (range != null) { MessageBox.Show(range.text); } } i found this the problem is without selecting the data is not fetched . i dont want to select any thing i just want to fetch the data on its own – user1379584 Jun 01 '12 at 13:18
-
i actually want to fetch the data which is shown on web service url so i told that. please help me in doing that. i found a link http://stackoverflow.com/questions/5099792/how-to-get-content-in-webbrowser-control?answertab=oldest#tab-top but it is not so help full so i am asking a question – user1379584 Jun 01 '12 at 13:23
-
Hi blam you talked about wsdl.exe can you please provide info on it – user1379584 Jun 04 '12 at 06:49
-
i want have an application which uses wsdl.exe to create wsdl files at run time – user1379584 Jun 04 '12 at 09:04
1 Answers
1
You can use the HttpWebRequest and HttpWebResponse objects from System.Net to communicate with a webserver.
e.g.
string GetWebPage(string address)
{
string responseText;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(address);
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
using (StreamReader responseStream = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("utf-8")))
{
responseText = responseStream.ReadToEnd();
}
}
return responseText;
}
You can then set the text of your textbox using:
myTextBox.Text = GetWebPage(address);
To make things nicer for your users, you should make the web requests asynchronous, so you don't lock up the UI while the data is downloading. You could use a BackgroundWorkerThread
to do this.

roomaroo
- 5,831
- 4
- 31
- 31
-
This is the error message i am getting The remote server returned an error: (401) Unauthorized. – user1379584 Jun 04 '12 at 06:25
-
The 401 error is because the website requires authentication - e.g. a username and password. If you visit the website in a normal browser does it prompt you to login? – roomaroo Jun 06 '12 at 15:10