yoni2
yoni2

Reputation: 111

Download HTML Page in C#

I am writing an app in c#, Is there a way to download a HTML page by giving my program its URL only. Foe example my program will get the URL www.google.com and download the HTML page?

Upvotes: 6

Views: 17147

Answers (2)

Jan
Jan

Reputation: 16032

Use the WebClient class.

This is extracted from a sample on the msdn doc page:

using System;
using System.Net;
using System.IO;

public static string Download (string uri)
{
    WebClient client = new WebClient ();

    Stream data = client.OpenRead (uri);
    StreamReader reader = new StreamReader (data);
    string s = reader.ReadToEnd ();
    data.Close ();
    reader.Close ();
    return s;
}

Upvotes: 8

Bas
Bas

Reputation: 27085

Use WebClient.DownloadString().

Upvotes: 17

Related Questions