Windows apps
Collapse the table of content
Expand the table of content
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

WebClient.BaseAddress Property

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

[Visual Basic]
Public Property BaseAddress As String
public string BaseAddress {get; set;}
public: __property String* get_BaseAddress();
public: __property void set_BaseAddress(String*);
public function get BaseAddress() : String;
public function set BaseAddress(String);

Property Value

The base URI for requests made by a WebClient.


Exception Type Condition
ArgumentException BaseAddress is set to an invalid URI.


The BaseAddress property contains a base URI that is combined with the relative address specified when calling an upload or download method.

If the BaseAddress property is set, the URI specified when calling the following methods must be a relative URI:


[Visual Basic, C#, C++] The following example downloads data from an Internet server and displays it on the console. It assumes that the server's address (such as is in hostUri and that the path to the resource (such as/default.htm) is in uriSuffix.

[Visual Basic] 
' 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."))

// Create a new WebClient instance.
WebClient myWebClient = new WebClient();

// Set the BaseAddress of the Web Resource in the WebClient.
myWebClient.BaseAddress = hostUri;
Console.WriteLine("Downloading from " + hostUri + "/" + uriSuffix);
Console.WriteLine("\nPress Enter key to continue");
// Download the target Web Resource into a byte array.
byte[] myDatabuffer = myWebClient.DownloadData (uriSuffix);

// Display the downloaded data.
string download = Encoding.ASCII.GetString(myDatabuffer);

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

// Create a new WebClient instance.
WebClient* myWebClient = new WebClient();

// Set the BaseAddress of the Web Resource in the WebClient.
myWebClient->BaseAddress = hostUri;
Console::WriteLine(S"Downloading from {0}/ {1}", hostUri, uriSuffix);
Console::WriteLine(S"\nPress Enter key to continue");

// Download the target Web Resource into a Byte array.
Byte myDatabuffer[] = myWebClient->DownloadData (uriSuffix);

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

Console::WriteLine(S"Download of {0}{1} was successful.", myWebClient->BaseAddress, uriSuffix);

[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

© 2017 Microsoft