This documentation is archived and is not being maintained.

WebClient.DownloadData Method

Downloads data from a resource with the specified URI.

[Visual Basic]
Public Function DownloadData( _
   ByVal address As String _
) As Byte()
public byte[] DownloadData(
 string address
public: unsigned char DownloadData(
 String* address
)  __gc[];
public function DownloadData(
   address : String
) : Byte[];


The URI to download data from.

Return Value

A byte array containing the data downloaded from the resource specified in the address parameter.


Exception Type Condition
WebException The URI formed by combining BaseAddress and address is invalid.


An error occurred while downloading data.


The DownloadData method downloads the data from the URI specified by the address parameter to a local byte array.

If the BaseAddress property is not empty, address must be a relative URI that is combined with BaseAddress to form the absolute URI of the requested data. If the QueryString property is not empty, it is appended to address.


[Visual Basic, C#, C++] The following example requests data from a server and displays the data returned. It assumes that remoteUri contains a valid URI for the requested data.

[Visual Basic] 
    Console.Write(ControlChars.Cr + "Please enter a Url(e.g. ")
    Dim remoteUrl As String = Console.ReadLine()            
    ' Create a new WebClient instance.
    Dim myWebClient As New WebClient()
    ' Download the home page data.
    Console.WriteLine(("Downloading " + remoteUrl))
    ' DownloadData() method takes a 'uriRemote.ToString()' and downloads the Web resource and saves it into a data buffer.
    Dim myDatabuffer As Byte() = myWebClient.DownloadData(remoteUrl)

    ' Display the downloaded data.
Dim download as String = Encoding.ASCII.GetString(myDataBuffer)

    Console.WriteLine("Download successful.")

// Create a new WebClient instance.
WebClient myWebClient = new WebClient();
// Download home page data.
Console.WriteLine("Downloading " + remoteUri);                        
// Download the Web resource and save it into a data buffer.
byte[] myDataBuffer = myWebClient.DownloadData (remoteUri);

// Display the downloaded data.
string download = Encoding.ASCII.GetString(myDataBuffer);
Console.WriteLine("Download successful.");

// Create a new WebClient instance.
WebClient* myWebClient = new WebClient();
// Download home page data.
Console::WriteLine(S"Downloading {0}", remoteUri);
// Download the Web resource and save it into a data buffer.
Byte myDataBuffer[] = myWebClient->DownloadData (remoteUri);

// Display the downloaded data.
String* download = Encoding::ASCII->GetString(myDataBuffer);

Console::WriteLine(S"Download successful.");

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.


Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, Common Language Infrastructure (CLI) Standard

See Also

WebClient Class | WebClient Members | System.Net Namespace