C# WebClient OpenRead(String)

Description

WebClient OpenRead(String) Opens a readable stream for the data downloaded from a resource with the URI specified as a String.

Syntax

WebClient.OpenRead(String) has the following syntax.


public Stream OpenRead(
  string address
)

Parameters

WebClient.OpenRead(String) has the following parameters.

  • address - The URI specified as a String from which to download data.

Returns

WebClient.OpenRead(String) method returns A Stream used to read data from a resource.

Example

The following code example opens the resource identified by uriString and displays the results on the system console.


using System;/* w ww. j  av a  2s .  c om*/
using System.Net;
using System.Net.Sockets;
using System.IO;

public class Example
{
    public static void Main()
    {
        WebClient myWebClient = new WebClient();
        Stream myStream = myWebClient.OpenRead("http://java2s.com");

        StreamReader sr = new StreamReader(myStream);
        Console.WriteLine(sr.ReadToEnd());
        myStream.Close();

    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Net »




Cookie
Dns
IPAddress
IPEndPoint
IPHostEntry
WebClient