Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

WebClient.BaseAddress Property

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

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

public string BaseAddress { get; set; }
/** @property */
public String get_BaseAddress ()

/** @property */
public void set_BaseAddress (String value)

public function get BaseAddress () : String

public function set BaseAddress (value : String)

Not applicable.

Property Value

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

ArgumentException

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 a null reference (Nothing in Visual Basic) 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.
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");
Console.ReadLine();    

// 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);

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.set_BaseAddress(hostUri);
Console.WriteLine("Downloading from " + hostUri + "/" + uriSuffix);
Console.WriteLine("\nPress Enter key to continue");
Console.ReadLine();
// Download the target Web Resource into a byte array.
ubyte myDatabuffer[] = myWebClient.DownloadData(uriSuffix);
// Display the downloaded data.
String download = Encoding.get_ASCII().GetString(myDatabuffer);
Console.WriteLine(download);

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

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.