Click here to Skip to main content
15,889,034 members
Articles / Programming Languages / C#
Tip/Trick

Get WebPage SourceCode

Rate me:
Please Sign up or sign in to vote.
3.00/5 (6 votes)
21 Apr 2011CPOL 14.3K   6   3
you will need to add
C#
using System.Net;


C#
private static String webSource(String url)
            {
                return Encoding.ASCII.GetString(new WebClient().DownloadData(WebRequest.Create(url).GetResponse().ResponseUri));
            }


or you could also use

C#
    private static String webSource(String url)
{
    return Encoding.ASCII.GetString(new WebClient().DownloadData(url));
}

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
I do not claim to be wrong! I just rarely ever write.

Comments and Discussions

 
GeneralMy vote of 5 Pin
ali_heidari_11-Feb-13 18:58
ali_heidari_11-Feb-13 18:58 
GeneralNot all pages use ASCII encoding. You'd be better off using ... Pin
Richard Deeming28-Apr-11 12:00
mveRichard Deeming28-Apr-11 12:00 
Generalif your going to vote atleast leave a comment explaining the... Pin
charles henington22-Apr-11 4:57
charles henington22-Apr-11 4:57 
if your going to vote atleast leave a comment explaining the reason for you vote. It works and much smaller code than most

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.