DownloadFile Method


DownloadFile Method

Location

My.Computer.Network.DownloadFile

Syntax

     My.Computer.Network.DownloadFile(address, destinationFileName _        [, username, password [, showUI, connectionTimeout, _        overwrite [, onUserCancel]]]) 

or:

     My.Computer.Network.DownloadFile(uri, destinationFileName _        [, username, password [, showUI, connectionTimeout, _        overwrite [, onUserCancel]]]) 

or:

     My.Computer.Network.DownloadFile(uri, destinationFileName, _        networkCredentials, showUI, connectionTimeout, overwrite _    [, onUserCancel]) 


address (required in syntax 1; String)

The file to download, including its full URL path.


uri (required in syntax 2 and 3; System.URI)

The uniform resource identifier (URI) of the file to download.


destinationFileName (required; String)

The local destination path for the downloaded file.


username (optional; String)

The network user name for authentication purposes. If supplied, password must also be used.


password (optional; String)

The network password for authentication purposes. If supplied, username must also be used.


showUI (optional; Boolean)

Indicates whether a progress window should appear during the download. By default, no progress window appears.


connectionTimeout (optional; Integer)

The number of seconds to wait before failure. By default, the timeout is 100 seconds.


overwrite (optional; Boolean)

Indicates whether any existing file at the destination location should be overwritten. By default, existing files are not overwritten.


onUserCancel (optional; UICancelOption enumeration)

The progress window includes a Cancel button. When pressed, the method takes action based on this parameter. One of the following Microsoft.VisualBasic.FileIO.UICancelOption enumeration values.

Value

Description

DoNothing

Aborts the download but returns no information indicating that the download was cancelled

THRowException

Throws an exception


If this parameter is missing, ThrowException is used by default.


networkCredentials (required in syntax 3; ICredentials interface)

The credentials to be supplied for authentication purposes, based on the System.Net.ICredentials interface.

Description

The DownloadFile method downloads a file from a network location, saving it in a specified destination on the local computer.

Usage at a Glance

  • An exception is thrown if the source or destination path is invalid, or if the source web site denies the request.

  • An exception is thrown if the user has invalid or insufficient security permissions to perform the download.

  • An exception is thrown if a connection timeout occurs due to a lack of server response.

Example

The following example downloads a file from a web site and saves it to a path on the local hard drive.

     My.Computer.Network.DownloadFile _        ("http://www.oreilly.com/PriceList.txt", "C:\PriceList.txt") 

Related Framework Entries

  • Microsoft.VisualBasic.Devices.Network.DownloadFile Method

See Also

Network Object, UploadFile Method




Visual Basic 2005(c) In a Nutshell
Visual Basic 2005 in a Nutshell (In a Nutshell (OReilly))
ISBN: 059610152X
EAN: 2147483647
Year: 2004
Pages: 712

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net