Export (0) Print
Expand All

WebClient.BaseAddress Property

Gets or sets the base URI for requests made by a WebClient.

Namespace:  System.Net
Assembly:  System (in System.dll)

Public Property BaseAddress As String

Property Value

Type: System.String
A String containing the base URI for requests made by a WebClient or Empty if no base address has been specified.


BaseAddress is set to an invalid URI. The inner exception may contain information that will help you locate the error.

The BaseAddress property contains a base URI that is combined with a relative address. When you call a method that uploads or downloads data, the WebClient object combines this base URI with the relative address you specify in the method call. If you specify an absolute URI, WebClient does not use the BaseAddress property value.

To remove a previously set value, set this property to Nothing or an empty string ("").

The following code example downloads data from an Internet server and displays it on the console. It assumes that the server's address (such as http://www.contoso.com) is in hostUri and that the path to the resource (such as /default.htm) is in uriSuffix.

            ' Create a new WebClient instance. 
            Dim myWebClient As New WebClient()

            ' Set the BaseAddress of the Web resource in the WebClient.
            myWebClient.BaseAddress = hostUri
            Console.WriteLine(("Downloading from " + hostUri + "/" + uriSuffix))
            Console.WriteLine(ControlChars.Cr + "Press Enter key to continue")

            ' Download the target Web resource into a byte array. 
            Dim myDatabuffer As Byte() = myWebClient.DownloadData(uriSuffix)

            ' Display the downloaded data. 
	    Dim download As String = Encoding.ASCII.GetString(myDatabuffer)

            Console.WriteLine(("Download of " + myWebClient.BaseAddress.ToString() + uriSuffix + " was successful."))

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Supported in: Windows Phone 8.1

Supported in: Windows Phone Silverlight 8.1

Supported in: Windows Phone Silverlight 8
© 2015 Microsoft