How to get html to string

  • Thread starter Thread starter Guest
  • Start date Start date
Hi,
You can create WebRequest passing Url and Get webResponse .
Get ResponseStream from WebResponse and read it into a String

Still if you have problem , let me know

ABCL
 
Hello ozulku_omer,

o> I want to have www.msdn.microsoft.com 's html code in a string ? What
o> can i do to have it?

// Address of URL
string URL = textBox1.Text;
try
{
// Get HTML data
WebClient client = new WebClient();
Stream data = client.OpenRead(URL);
StreamReader reader = new StreamReader(data);
string str = "";
str = reader.ReadLine();

while( str != null)
{
Console.WriteLine(str);
str = reader.ReadLine();
}
data.Close();
}
catch(WebException exp)
{
MessageBox.Show(exp.Message, "Exception");
}


---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/members/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
 
Hi Omer,

Here is the Code for converting HTml into string

string result = string.Empty;

WebRequest wrq = WebRequest.Create(Url);
WebResponse wrs = wrq.GetResponse();

StreamReader strdr = new StreamReader(wrs.GetResponseStream());
result = strdr.ReadToEnd();

strdr.Close();
wrs.Close();
 
Back
Top