Reputation: 151
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.
Upvotes: 1
Views: 4008
Reputation: 5881
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.
Upvotes: 1