471,319 Members | 2,689 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,319 software developers and data experts.

How to get html to string

Hi all,

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


Dec 23 '05 #1
3 15632
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


Dec 23 '05 #2
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;
// 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)
str = reader.ReadLine();
catch(WebException exp)
MessageBox.Show(exp.Message, "Exception");
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
Dec 23 '05 #3
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();


Dec 24 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by Wouter vanEck | last post: by
3 posts views Thread by Just D. | last post: by
2 posts views Thread by csgraham74 | last post: by
1 post views Thread by eggie5 | last post: by
4 posts views Thread by =?Utf-8?B?VGVycnk=?= | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.