CSharp.Net-Informations.com
   Home      .Net Framework      VB.NET      C#                                                                      About


  How to read URL Content from webserver

The .NET framework provides two namespaces, System.Net and System.Net.Sockets for network programming. The System.Net classes use to communicate with other applications by using the HTTP, TCP, UDP and Sockets.

When we want to read the content of an HTML page from a remote webserver in C# we are using WebRequest and WebResponse Classes. WebResponse return a StreamReader and we can get the content from StreamReader . The following C# program shows how to read the content of an HTML page using WebRequest and WebResponse Classes.

         C# Source Code Download           Print Source Code
         How to read URL Content from webserver - Download
        
C# Tutorial

using System;
using System.Windows.Forms;
using System.Net;
using System.IO;

namespace WindowsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                StreamReader inStream ;
                WebRequest webRequest ;
                WebResponse webresponse ;
                webRequest = WebRequest.Create(textBox1.Text);
                webresponse = webRequest.GetResponse();
                inStream = new StreamReader(webresponse.GetResponseStream());
                textBox2.Text = inStream.ReadToEnd();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
    }
}



CSharp Communications Related Contents
*     How to send email from C#
*     How to send email with attachment from C#
*     How to send html email from C#
*     How to send cdo email from C#
*     How to find hostname of a computer
*     How to find IP Adress of a computer
*     How to C# Socket programming
*     C# Server Socket program
*     C# Client Socket program
*     C# Multi threaded socket programming
*     C# Multi threaded Server Socket programming
*     C# Multi threaded Client Socket programming
*     How to C# Chat server programming
*     How to C# Chat Server
*     How to C# Chat Client


   Home      VB.NET      C#
CSharp Related Topics
*     An overview of Microsoft CSharp
*     C# Language Tutorial
*     C# Statements Tutorial
*     C# Collection Tutorial
*     C# String Tutorial
*     C# File Operations Tutorial
*     C# Excel Tutorial
*     C# Crystal Reports Tutorial
*     CSharp Communication Tutorial
*     C# Ado.Net Tutorial and Source Code
*     C# ADO.NET data Providers Tutorial
*     C# Dataset Tutorial
*     C# DataAdapater Tutorial
*     Csharp DataView Tutorial
*     Csharp Remoting Tutorial
*     C# XML Tutorial
*     C# DataGridView Tutorial
   Home      VB.NET      C#
More Source Code :   
Mail to :  feedback@net-informations.com
  |  Home   |  VB.NET   |  C#   |  SiteMap   |  Terms of Use   |  About   |
net-informations.com (C) 2010
All Rights Reserved. All other trademarks are property of their respective owners.