OpenURL Method

       

Opens and returns the document at the specified URL. The document is returned as a variant. When the method has completed, the URL properties (and portions of the URL such as the protocol) are updated to reflect the current URL.

Syntax

object.OpenUrl url [,datatype]

The OpenURL property syntax has these parts:

Part Description
object An object expression that evaluates to an object in the Applies To list.
url Required. The URL of the document to be retrieved.
datatype Optional. Integer that specifies the type of the data, as shown in Settings.

Settings

The settings for datatype are:

Constant Value Description
icString 0 Default. Retrieves data as string.
icByteArray 1 Retrieves data as a byte array.

Return Type

Variant

Remarks

The OpenURL method's return value depends on the target of the URL. For example, if the target URL is the directory of an FTP server, the directory will be returned. On the other hand, if the target is a file, the file will be retrieved.

The OpenURL method is equivalent to invoking the Execute method with a GET operation, followed by a GetChunk method invoked in the StateChanged event. The OpenURL method, however, results in a synchronous stream of data being returned from the site.

If you are retrieving a binary file, be sure to use a byte array as a temporary variable before writing it to disk, as shown below:

Dim b() As Byte
Dim strURL As String
' Set the strURL to a valid address.
strURL = "FTP://ftp.GreatSite.com/China.exe"
b() = Inet1.OpenURL(strURL, icByteArray)

Open "C:\Temp\China.exe" For Binary Access _
Write As #1
Put #1, , b()
Close #1

Note   When using the OpenURL method, set the URL property before you set the Password and UserName properties. If you set the URL property last, the UserName and Password properties will be set to "".