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.

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

Property Value

The base URI for requests made by a WebClient.

Exceptions

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

Remarks

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:

Example

[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 http://www.contoso.com) 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")
Console.ReadLine()

' 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)

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

[C#] 
// 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.");

[C++] 
// 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");
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(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.

Requirements

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

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.