Click here to Skip to main content
13,287,658 members (46,267 online)
Click here to Skip to main content
Add your own
alternative version


37 bookmarked
Posted 31 Jul 2009

Get HTML Source from User Defined Web Address

, 31 Jul 2009
Rate this:
Please Sign up or sign in to vote.
A very easy way to get HTML source from user defined web address


Figure 1: HTML Source


Figure 2: Web Browser


Give me your web address, I will return to you the HTML source. This article will demonstrate to you a very effortless way to do this.


HTTP post & HTTP reply are very common concepts. Some time ago, I had a little interest in that, so I tried to understand the features of .NET framework library. It was an excellent experience, it’s huge! & my interest went up. All of a sudden, I understand the use of the classes, HttpWebRequest & HttpWebResponse, which will be found at System.Net namespace & I tried to implement this idea.

Using the Code

This is a very simple method. I just use the following classes:

  1. HttpWebRequest 
  2. HttpWebResponse 
  3. StreamReader


Provides an HTTP-specific implementation of the WebRequest class. The HttpWebRequest class provides support for the properties and methods defined in WebRequest and for additional properties and methods that enable the user to interact directly with servers using HTTP.

More details can be found at this link.


Provides an HTTP-specific implementation of the WebResponse class. This class contains support for HTTP-specific uses of the properties and methods of the WebResponse class. The HttpWebResponse class is used to build HTTP stand-alone client applications that send HTTP requests and receive HTTP responses.

More details can be found at this link.


Implements a TextReader that reads characters from a byte stream in a particular encoding.
StreamReader is designed for character input in a particular encoding, whereas the Stream class is designed for byte input and output. Use StreamReader for reading lines of information from a standard text file. 

StreamReader defaults to UTF-8 encoding unless specified otherwise, instead of defaulting to the ANSI code page for the current system. UTF-8 handles Unicode characters correctly and provides consistent results on localized versions of the operating system.
By default, a StreamReader is not thread safe. See TextReader..::.Synchronized for a thread-safe wrapper.

The Read(array<Char>[]()[], Int32, Int32) and Write(array<Char>[]()[], Int32, Int32) method overloads read and write the number of characters specified by the count parameter. These are to be distinguished from BufferedStream..::.Read and BufferedStream..::.Write , which read and write the number of bytes specified by the count parameter. Use the BufferedStream methods only for reading and writing an integral number of byte array elements.

More details can be found at this link.

Sample Code Example

// Button event
Private Sub ButtonGet_Click(ByVal sender As System.Object, _
	ByVal e As System.EventArgs) Handles ButtonGet.Click
        Dim objGetSource As GetSource = New GetSource()
            If Me.TextBoxWebAddress.Text.Trim <> vbNullString Then
                Me.RichTextBoxHTMLSource.Text = _
            End If
        Catch ex As Exception
        End Try
End Sub 
// Get HTML Source class 
Imports System
Imports System.IO
Imports System.Web

Public Class GetSource
    Function GetHTML(ByVal strPage As String) As String
        Dim strReply As String = "NULL"
        'Dim objErr As ErrObject

            Dim objHttpRequest As System.Net.HttpWebRequest
            Dim objHttpResponse As System.Net.HttpWebResponse
            objHttpRequest = System.Net.HttpWebRequest.Create(strPage)
            objHttpResponse = objHttpRequest.GetResponse
            Dim objStrmReader As New StreamReader(objHttpResponse.GetResponseStream)

            strReply = objStrmReader.ReadToEnd()

        Catch ex As Exception
            strReply = "ERROR! " + ex.Message.ToString
        End Try

        Return strReply

    End Function
End Class


I hope that you will like it. Enjoy!


  • 1st August, 2009: Initial post


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


About the Author

Md. Marufuzzaman
Bangladesh Bangladesh
A well experienced leader with successful track record of software development, product innovations, brand management and corporate communication etc. Some successful product innovations have also achieved and awards “Most Valuable Professional” (MVP) at 2010 and 2011 by and also selected as a mentor of Published over 100 technical articles in various software development resource sites (i.e.,, Microsoft MSDN, and IEEE & IBM (In progress)) and various IT Forums, Blogs etc.

Over twelve years of professional experiences in ICT field having extensive experience in formulating corporate vision and long term strategy. Leading development related functions including design, development, services, data management and analytics, customer experience management, content services, digital analytics and optimization.I have also more than two years’ of strong experience in mobile-VAS (platform development).

An individual with results-driven approach and relentless in pursuit of excellence from a business and organizational standpoint.Honest, believes in transparency, commitment and teamwork.

Expertise: Software/Solution Architect, Research, MIS, Data Analytics, Data Mining, BI, SaaS platform base application development, Large scale Win32 Form/Web based business software solutions, Security, Enterprise applications development, integration, etc.

Technologies/Tools: Microsoft.Net version 05/08/10/12, Microsoft SQL Server version 7/2K/05/08/12/14 , Oracle version 10/11, MySql version 5.1, 5.5, 5.7, Visual C#, VB.NET, ASP.NET, API, MVC, WebAPI , WPF, WCF, PHP, Microsoft Power BI, SPSS, PS2, R, Add-In, Visual Basic etc.

.Net UI component: Telerik, DevExpress, Ext.Net.
Scripting language: JavaScript, AngularJS, node.JS.
Source control / Subversion: Git,SVN.
Development methodologies: Agile,RAD.
Project Management / Issues Tracking Tools: JIRA, ClockingIt.

You may also be interested in...


Comments and Discussions

GeneralWebClient Pin
CP Greendrop1-Aug-09 5:39
memberCP Greendrop1-Aug-09 5:39 
GeneralRe: WebClient Pin
Md. Marufuzzaman1-Aug-09 7:25
groupMd. Marufuzzaman1-Aug-09 7:25 
GeneralRe: WebClient Pin
Md. Marufuzzaman1-Aug-09 8:43
groupMd. Marufuzzaman1-Aug-09 8:43 
GeneralNice! Pin
rspercy6031-Jul-09 11:41
memberrspercy6031-Jul-09 11:41 
GeneralRe: Nice! Pin
Md. Marufuzzaman31-Jul-09 11:50
groupMd. Marufuzzaman31-Jul-09 11:50 

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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.171207.1 | Last Updated 31 Jul 2009
Article Copyright 2009 by Md. Marufuzzaman
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid