views:

56

answers:

2

How can I load a web-page into a string in .net ?

i want the fastest way possible ...

+5  A: 

You could try the DownloadString method:

using (var client = new WebClient())
{
    string result = client.DownloadString("http://www.google.com/");
}

VB.NET equivalent:

Using client = New WebClient()
    Dim result As String = client.DownloadString("http://www.google.com/")
End Using
Darin Dimitrov
is this C#...not ...vb ...is this the faster way?
Adrian
Yes it is C#. Faster than what?
Darin Dimitrov
Given that you didn't tag your question as VB, how are we meant to guess?
spender
I'm sure he means "fastest". Adrian: I'll bet you can bypass the Windows and poll your NIC hardware directly to get the "fastest" possible speed. Don't worry about it, though. Darin's answer is the best you're going to get within a reasonable programming environment.
Michael Petrotta
@Adrian, posted VB.NET equivalent.
Darin Dimitrov
thanks! its working!
Adrian
+1  A: 

Short of writing your own HTTP client, you're pretty much stuck with WebRequest or WebClient (which leverages WebRequest for its work). A component of our website relies on downloading data from other webpages, and we recently replaced all of the code reliant on WebRequest/HttpWebRequest with our own Socket based code and gained considerable CPU cycles back, but it's a tricky job that will take one dev who is very familiar with HTTP protocol at least a week to complete. Not for the faint of heart.

spender