Network.DownloadFile Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Downloads the specified remote file and saves it in the specified location.
Overloads
DownloadFile(String, String) |
Downloads the specified remote file and saves it in the specified location. |
DownloadFile(Uri, String) |
Downloads the specified remote file and saves it in the specified location. |
DownloadFile(String, String, String, String) |
Downloads the specified remote file and saves it in the specified location. |
DownloadFile(Uri, String, String, String) |
Downloads the specified remote file and saves it in the specified location. |
DownloadFile(Uri, String, ICredentials, Boolean, Int32, Boolean) |
Downloads the specified remote file and saves it in the specified location. |
DownloadFile(String, String, String, String, Boolean, Int32, Boolean) |
Downloads the specified remote file and saves it in the specified location. |
DownloadFile(Uri, String, ICredentials, Boolean, Int32, Boolean, UICancelOption) |
Downloads the specified remote file and saves it in the specified location. |
DownloadFile(Uri, String, String, String, Boolean, Int32, Boolean) |
Downloads the specified remote file and saves it in the specified location. |
DownloadFile(String, String, String, String, Boolean, Int32, Boolean, UICancelOption) |
Downloads the specified remote file and saves it in the specified location. |
DownloadFile(Uri, String, String, String, Boolean, Int32, Boolean, UICancelOption) |
Downloads the specified remote file and saves it in the specified location. |
DownloadFile(String, String)
- Source:
- Network.vb
- Source:
- Network.vb
- Source:
- Network.vb
Downloads the specified remote file and saves it in the specified location.
public:
void DownloadFile(System::String ^ address, System::String ^ destinationFileName);
public void DownloadFile (string address, string destinationFileName);
member this.DownloadFile : string * string -> unit
Public Sub DownloadFile (address As String, destinationFileName As String)
Parameters
- address
- String
Path of the file to download, including file name and host address.
- destinationFileName
- String
File name and path of the downloaded file.
Exceptions
destinationFileName
ends with a trailing slash.
The server does not respond within the default timeout (100 seconds).
User lacks necessary permissions to perform a network operation.
The request is denied by the target web server.
Examples
This example downloads the file WineList.txt
from http://www.cohowinery.com/downloads
and saves it to C:\Documents and Settings\All Users\Documents
.
My.Computer.Network.DownloadFile(
"http://www.cohowinery.com/downloads/WineList.txt",
"C:\Documents and Settings\All Users\Documents\WineList.txt")
This example downloads the file WineList.txt
from http://www.cohowinery.com/downloads
and saves it to C:\Documents and Settings\All Users\Documents
, specifying a timeout interval of 500 milliseconds.
My.Computer.Network.DownloadFile(
"http://www.cohowinery.com/downloads/",
"C:\Documents and Settings\All Users\Documents\WineList.txt",
"", "", False, 500, True)
Remarks
If the destination file already exists, the DownloadFile
method will not overwrite the existing file. You can use one of the other overloads of the DownloadFile method to instruct it to overwrite existing files, provide user credentials, or specify a specific timeout value.
DownloadFile
outputs trace information when you enable network tracing in your application. For more information, see Enabling Network Tracing.
Note
The DownloadFile
method does not send optional HTTP headers. Some servers may return 500 (Internal Server Error) if the optional user agent header is missing. To send optional headers, you must construct a request using the WebClient class.
The following table lists an example of a task involving the My.Computer.Network.DownloadFile
method.
To | See |
---|---|
Download a file | How to: Download a File |
See also
- Uri
- ICredentials
- Objects (Visual Basic)
- How to: Download a File in Visual Basic
- How to: Parse File Paths in Visual Basic
Applies to
DownloadFile(Uri, String)
- Source:
- Network.vb
- Source:
- Network.vb
- Source:
- Network.vb
Downloads the specified remote file and saves it in the specified location.
public:
void DownloadFile(Uri ^ address, System::String ^ destinationFileName);
public void DownloadFile (Uri address, string destinationFileName);
member this.DownloadFile : Uri * string -> unit
Public Sub DownloadFile (address As Uri, destinationFileName As String)
Parameters
- address
- Uri
Path of the file to download, including file name and host address.
- destinationFileName
- String
File name and path of the downloaded file.
Exceptions
destinationFileName
ends with a trailing slash.
The server does not respond within the default timeout (100 seconds).
User lacks necessary permissions to perform a network operation.
The request is denied by the target web server.
Examples
This example downloads the file WineList.txt
from http://www.cohowinery.com/downloads
and saves it to C:\Documents and Settings\All Users\Documents
.
My.Computer.Network.DownloadFile(
"http://www.cohowinery.com/downloads/WineList.txt",
"C:\Documents and Settings\All Users\Documents\WineList.txt")
This example downloads the file WineList.txt
from http://www.cohowinery.com/downloads
and saves it to C:\Documents and Settings\All Users\Documents
, specifying a timeout interval of 500 milliseconds.
My.Computer.Network.DownloadFile(
"http://www.cohowinery.com/downloads/",
"C:\Documents and Settings\All Users\Documents\WineList.txt",
"", "", False, 500, True)
Remarks
If the destination file already exists, the DownloadFile
method will not overwrite the existing file. You can use one of the other overloads of the DownloadFile method to instruct it to overwrite existing files, provide user credentials, or specify a specific timeout value. DownloadFile
outputs trace information when you enable network tracing in your application. For more information, see Enabling Network Tracing.
Note
The DownloadFile
method does not send optional HTTP headers. Some servers may return 500 (Internal Server Error) if the optional user agent header is missing. To send optional headers, you must construct a request using the WebClient class.
The following table lists an example of a task involving the My.Computer.Network.DownloadFile
method.
To | See |
---|---|
Download a file | How to: Download a File |
See also
- Uri
- ICredentials
- Objects (Visual Basic)
- How to: Download a File in Visual Basic
- How to: Parse File Paths in Visual Basic
Applies to
DownloadFile(String, String, String, String)
- Source:
- Network.vb
- Source:
- Network.vb
- Source:
- Network.vb
Downloads the specified remote file and saves it in the specified location.
public:
void DownloadFile(System::String ^ address, System::String ^ destinationFileName, System::String ^ userName, System::String ^ password);
public void DownloadFile (string address, string destinationFileName, string userName, string password);
member this.DownloadFile : string * string * string * string -> unit
Public Sub DownloadFile (address As String, destinationFileName As String, userName As String, password As String)
Parameters
- address
- String
Path of the file to download, including file name and host address.
- destinationFileName
- String
File name and path of the downloaded file.
- userName
- String
User name to authenticate. Default is an empty string, "".
- password
- String
Password to authenticate. Default is an empty string, "".
Exceptions
destinationFileName
ends with a trailing slash.
The server does not respond within the default timeout (100 seconds).
User lacks necessary permissions to perform a network operation.
The request is denied by the target web server.
Examples
This example downloads the file WineList.txt
from http://www.cohowinery.com/downloads
and saves it to C:\Documents and Settings\All Users\Documents
.
My.Computer.Network.DownloadFile(
"http://www.cohowinery.com/downloads/WineList.txt",
"C:\Documents and Settings\All Users\Documents\WineList.txt")
This example downloads the file WineList.txt
from http://www.cohowinery.com/downloads
and saves it to C:\Documents and Settings\All Users\Documents
, specifying a timeout interval of 500 milliseconds.
My.Computer.Network.DownloadFile(
"http://www.cohowinery.com/downloads/",
"C:\Documents and Settings\All Users\Documents\WineList.txt",
"", "", False, 500, True)
Remarks
If the destination file already exists, the DownloadFile
method will not overwrite the existing file. You can use one of the other overloads of the DownloadFile method to instruct it to overwrite existing files or specify a specific timeout value.
DownloadFile
outputs trace information when you enable network tracing in your application. For more information, see Enabling Network Tracing.
Note
The DownloadFile
method does not send optional HTTP headers. Some servers may return 500 (Internal Server Error) if the optional user agent header is missing. To send optional headers, you must construct a request using the WebClient class.
Note
The FTP protocol sends information, including passwords, in plain text and should not be used for transmitting sensitive information.
The following table lists an example of a task involving the My.Computer.Network.DownloadFile
method.
To | See |
---|---|
Download a file | How to: Download a File |
See also
- Uri
- ICredentials
- Objects (Visual Basic)
- How to: Download a File in Visual Basic
- How to: Parse File Paths in Visual Basic
Applies to
DownloadFile(Uri, String, String, String)
- Source:
- Network.vb
- Source:
- Network.vb
- Source:
- Network.vb
Downloads the specified remote file and saves it in the specified location.
public:
void DownloadFile(Uri ^ address, System::String ^ destinationFileName, System::String ^ userName, System::String ^ password);
public void DownloadFile (Uri address, string destinationFileName, string userName, string password);
member this.DownloadFile : Uri * string * string * string -> unit
Public Sub DownloadFile (address As Uri, destinationFileName As String, userName As String, password As String)
Parameters
- address
- Uri
Path of the file to download, including file name and host address.
- destinationFileName
- String
File name and path of the downloaded file.
- userName
- String
User name to authenticate. Default is an empty string, "".
- password
- String
Password to authenticate. Default is an empty string, "".
Exceptions
destinationFileName
ends with a trailing slash.
The server does not respond within the default timeout (100 seconds).
User lacks necessary permissions to perform a network operation.
The request is denied by the target web server.
Examples
This example downloads the file WineList.txt
from http://www.cohowinery.com/downloads
and saves it to C:\Documents and Settings\All Users\Documents
.
My.Computer.Network.DownloadFile(
"http://www.cohowinery.com/downloads/WineList.txt",
"C:\Documents and Settings\All Users\Documents\WineList.txt")
This example downloads the file WineList.txt
from http://www.cohowinery.com/downloads
and saves it to C:\Documents and Settings\All Users\Documents
, specifying a timeout interval of 500 milliseconds.
My.Computer.Network.DownloadFile(
"http://www.cohowinery.com/downloads/",
"C:\Documents and Settings\All Users\Documents\WineList.txt",
"", "", False, 500, True)
Remarks
If the destination file already exists, the DownloadFile
method will not overwrite the existing file. You can use one of the other overloads of the DownloadFile method to instruct it to overwrite existing files or specify a specific timeout value.
DownloadFile
outputs trace information when you enable network tracing in your application. For more information, see Enabling Network Tracing.
Note
The DownloadFile
method does not send optional HTTP headers. Some servers may return 500 (Internal Server Error) if the optional user agent header is missing. To send optional headers, you must construct a request using the WebClient class.
Note
The FTP protocol sends information, including passwords, in plain text and should not be used for transmitting sensitive information.
The following table lists an example of a task involving the My.Computer.Network.DownloadFile
method.
To | See |
---|---|
Download a file | How to: Download a File |
See also
- Uri
- ICredentials
- Objects (Visual Basic)
- How to: Download a File in Visual Basic
- How to: Parse File Paths in Visual Basic
Applies to
DownloadFile(Uri, String, ICredentials, Boolean, Int32, Boolean)
- Source:
- Network.vb
- Source:
- Network.vb
- Source:
- Network.vb
Downloads the specified remote file and saves it in the specified location.
public:
void DownloadFile(Uri ^ address, System::String ^ destinationFileName, System::Net::ICredentials ^ networkCredentials, bool showUI, int connectionTimeout, bool overwrite);
public void DownloadFile (Uri address, string destinationFileName, System.Net.ICredentials networkCredentials, bool showUI, int connectionTimeout, bool overwrite);
member this.DownloadFile : Uri * string * System.Net.ICredentials * bool * int * bool -> unit
Public Sub DownloadFile (address As Uri, destinationFileName As String, networkCredentials As ICredentials, showUI As Boolean, connectionTimeout As Integer, overwrite As Boolean)
Parameters
- destinationFileName
- String
String
. File name and path of the downloaded file.
- networkCredentials
- ICredentials
ICredentials. Credentials to be supplied.
- showUI
- Boolean
True
to display the progress of the operation; otherwise False
. Default is False
.
- connectionTimeout
- Int32
Timeout interval, in milliseconds. Default is 100 seconds.
- overwrite
- Boolean
True
to overwrite existing files; otherwise False
. Default is False
.
Exceptions
destinationFileName
ends with a trailing slash.
overwrite
is set to False
and the destination file already exists.
The server does not respond within the specified connectionTimeout
.
User lacks necessary permissions to perform a network operation.
The request is denied by the target web server.
Examples
This example downloads the file WineList.txt
from http://www.cohowinery.com/downloads
and saves it to C:\Documents and Settings\All Users\Documents
.
My.Computer.Network.DownloadFile(
"http://www.cohowinery.com/downloads/WineList.txt",
"C:\Documents and Settings\All Users\Documents\WineList.txt")
This example downloads the file WineList.txt
from http://www.cohowinery.com/downloads
and saves it to C:\Documents and Settings\All Users\Documents
, specifying a timeout interval of 500 milliseconds.
My.Computer.Network.DownloadFile(
"http://www.cohowinery.com/downloads/",
"C:\Documents and Settings\All Users\Documents\WineList.txt",
"", "", False, 500, True)
Remarks
If showUI
is set to True
, a dialog box appears that shows the progress of the operation; the dialog box contains a Cancel button that can be used to cancel the operation. The dialog box is not modal, and therefore does not block user input to other windows in the program.
If the server does not respond within the specified connectionTimeout
, the operation is cancelled, and an exception is thrown.
DownloadFile
outputs trace information when you enable network tracing in your application. For more information, see Enabling Network Tracing.
Note
The DownloadFile
method does not send optional HTTP headers. Some servers may return 500 (Internal Server Error) if the optional user agent header is missing. To send optional headers, you must construct a request using the WebClient class.
Note
The FTP protocol sends information, including passwords, in plain text and should not be used for transmitting sensitive information.
The following table lists an example of a task involving the My.Computer.Network.DownloadFile
method.
To | See |
---|---|
Download a file | How to: Download a File |
See also
- Uri
- ICredentials
- Objects (Visual Basic)
- How to: Download a File in Visual Basic
- How to: Parse File Paths in Visual Basic
Applies to
DownloadFile(String, String, String, String, Boolean, Int32, Boolean)
- Source:
- Network.vb
- Source:
- Network.vb
- Source:
- Network.vb
Downloads the specified remote file and saves it in the specified location.
public:
void DownloadFile(System::String ^ address, System::String ^ destinationFileName, System::String ^ userName, System::String ^ password, bool showUI, int connectionTimeout, bool overwrite);
public void DownloadFile (string address, string destinationFileName, string userName, string password, bool showUI, int connectionTimeout, bool overwrite);
member this.DownloadFile : string * string * string * string * bool * int * bool -> unit
Public Sub DownloadFile (address As String, destinationFileName As String, userName As String, password As String, showUI As Boolean, connectionTimeout As Integer, overwrite As Boolean)
Parameters
- address
- String
Path of the file to download, including file name and host address.
- destinationFileName
- String
File name and path of the downloaded file.
- userName
- String
User name to authenticate. Default is an empty string, "".
- password
- String
Password to authenticate. Default is an empty string, "".
- showUI
- Boolean
True
to display the progress of the operation; otherwise False
. Default is False
.
- overwrite
- Boolean
True
to overwrite existing files; otherwise False
. Default is False
.
Exceptions
destinationFileName
ends with a trailing slash.
overwrite
is set to False
and the destination file already exists.
The server does not respond within the specified connectionTimeout
.
User lacks necessary permissions to perform a network operation.
The request is denied by the target web server.
Examples
This example downloads the file WineList.txt
from http://www.cohowinery.com/downloads
and saves it to C:\Documents and Settings\All Users\Documents
.
My.Computer.Network.DownloadFile(
"http://www.cohowinery.com/downloads/WineList.txt",
"C:\Documents and Settings\All Users\Documents\WineList.txt")
This example downloads the file WineList.txt
from http://www.cohowinery.com/downloads
and saves it to C:\Documents and Settings\All Users\Documents
, specifying a timeout interval of 500 milliseconds.
My.Computer.Network.DownloadFile(
"http://www.cohowinery.com/downloads/",
"C:\Documents and Settings\All Users\Documents\WineList.txt",
"", "", False, 500, True)
Remarks
If showUI
is set to True
, a dialog box appears that shows the progress of the operation; the dialog box contains a Cancel button that can be used to cancel the operation. The dialog box is not modal, and therefore does not block user input to other windows in the program.
If the server does not respond within the specified connectionTimeout
, the operation is cancelled, and an exception is thrown.
DownloadFile
outputs trace information when you enable network tracing in your application. For more information, see Enabling Network Tracing.
Note
The DownloadFile
method does not send optional HTTP headers. Some servers may return 500 (Internal Server Error) if the optional user agent header is missing. To send optional headers, you must construct a request using the WebClient class.
Note
The FTP protocol sends information, including passwords, in plain text and should not be used for transmitting sensitive information.
The following table lists an example of a task involving the My.Computer.Network.DownloadFile
method.
To | See |
---|---|
Download a file | How to: Download a File |
See also
- Uri
- ICredentials
- Objects (Visual Basic)
- How to: Download a File in Visual Basic
- How to: Parse File Paths in Visual Basic
Applies to
DownloadFile(Uri, String, ICredentials, Boolean, Int32, Boolean, UICancelOption)
- Source:
- Network.vb
- Source:
- Network.vb
- Source:
- Network.vb
Downloads the specified remote file and saves it in the specified location.
public:
void DownloadFile(Uri ^ address, System::String ^ destinationFileName, System::Net::ICredentials ^ networkCredentials, bool showUI, int connectionTimeout, bool overwrite, Microsoft::VisualBasic::FileIO::UICancelOption onUserCancel);
public void DownloadFile (Uri address, string destinationFileName, System.Net.ICredentials networkCredentials, bool showUI, int connectionTimeout, bool overwrite, Microsoft.VisualBasic.FileIO.UICancelOption onUserCancel);
member this.DownloadFile : Uri * string * System.Net.ICredentials * bool * int * bool * Microsoft.VisualBasic.FileIO.UICancelOption -> unit
Public Sub DownloadFile (address As Uri, destinationFileName As String, networkCredentials As ICredentials, showUI As Boolean, connectionTimeout As Integer, overwrite As Boolean, onUserCancel As UICancelOption)
Parameters
- address
- Uri
Path of the file to download, including file name and host address.
- destinationFileName
- String
File name and path of the downloaded file.
- networkCredentials
- ICredentials
Credentials to be supplied.
- showUI
- Boolean
True
to display the progress of the operation; otherwise False
. Default is False
.
- connectionTimeout
- Int32
Timeout interval, in milliseconds. Default is 100 seconds.
- overwrite
- Boolean
True
to overwrite existing files; otherwise False
. Default is False
.
- onUserCancel
- UICancelOption
Specifies behavior when the user clicks Cancel or No on the dialog box shown as a result of showUI
set to True
. Default is ThrowException.
Exceptions
destinationFileName
ends with a trailing slash.
overwrite
is set to False
and the destination file already exists.
The server does not respond within the specified connectionTimeout
.
User lacks necessary permissions to perform a network operation.
The request is denied by the target web server.
Examples
This example downloads the file WineList.txt
from http://www.cohowinery.com/downloads
and saves it to C:\Documents and Settings\All Users\Documents
.
My.Computer.Network.DownloadFile(
"http://www.cohowinery.com/downloads/WineList.txt",
"C:\Documents and Settings\All Users\Documents\WineList.txt")
This example downloads the file WineList.txt
from http://www.cohowinery.com/downloads
and saves it to C:\Documents and Settings\All Users\Documents
, specifying a timeout interval of 500 milliseconds.
My.Computer.Network.DownloadFile(
"http://www.cohowinery.com/downloads/",
"C:\Documents and Settings\All Users\Documents\WineList.txt",
"", "", False, 500, True)
Remarks
If showUI
is set to True
, a dialog box appears that shows the progress of the operation; the dialog box contains a Cancel button that can be used to cancel the operation. The dialog box is not modal, and therefore does not block user input to other windows in the program.
If the server does not respond within the specified connectionTimeout
, the operation is cancelled, and an exception is thrown.
DownloadFile
outputs trace information when you enable network tracing in your application. For more information, see Enabling Network Tracing.
Note
The DownloadFile
method does not send optional HTTP headers. Some servers may return 500 (Internal Server Error) if the optional user agent header is missing. To send optional headers, you must construct a request using the WebClient class.
Note
The FTP protocol sends information, including passwords, in plain text and should not be used for transmitting sensitive information.
The following table lists an example of a task involving the My.Computer.Network.DownloadFile
method.
To | See |
---|---|
Download a file | How to: Download a File |
See also
- Uri
- ICredentials
- Objects (Visual Basic)
- How to: Download a File in Visual Basic
- How to: Parse File Paths in Visual Basic
Applies to
DownloadFile(Uri, String, String, String, Boolean, Int32, Boolean)
- Source:
- Network.vb
- Source:
- Network.vb
- Source:
- Network.vb
Downloads the specified remote file and saves it in the specified location.
public:
void DownloadFile(Uri ^ address, System::String ^ destinationFileName, System::String ^ userName, System::String ^ password, bool showUI, int connectionTimeout, bool overwrite);
public void DownloadFile (Uri address, string destinationFileName, string userName, string password, bool showUI, int connectionTimeout, bool overwrite);
member this.DownloadFile : Uri * string * string * string * bool * int * bool -> unit
Public Sub DownloadFile (address As Uri, destinationFileName As String, userName As String, password As String, showUI As Boolean, connectionTimeout As Integer, overwrite As Boolean)
Parameters
- address
- Uri
Path of the file to download, including file name and host address.
- destinationFileName
- String
File name and path of the downloaded file.
- userName
- String
User name to authenticate. Default is an empty string, "".
- password
- String
Password to authenticate. Default is an empty string, "".
- showUI
- Boolean
True
to display the progress of the operation; otherwise False
. Default is False
.
- connectionTimeout
- Int32
Timeout interval, in milliseconds. Default is 100 seconds.
- overwrite
- Boolean
True
to overwrite existing files; otherwise False
. Default is False
.
Exceptions
destinationFileName
ends with a trailing slash.
overwrite
is set to False
and the destination file already exists.
The server does not respond within the specified connectionTimeout
.
User lacks necessary permissions to perform a network operation.
The request is denied by the target web server.
Examples
This example downloads the file WineList.txt
from http://www.cohowinery.com/downloads
and saves it to C:\Documents and Settings\All Users\Documents
.
My.Computer.Network.DownloadFile(
"http://www.cohowinery.com/downloads/WineList.txt",
"C:\Documents and Settings\All Users\Documents\WineList.txt")
This example downloads the file WineList.txt
from http://www.cohowinery.com/downloads
and saves it to C:\Documents and Settings\All Users\Documents
, specifying a timeout interval of 500 milliseconds.
My.Computer.Network.DownloadFile(
"http://www.cohowinery.com/downloads/",
"C:\Documents and Settings\All Users\Documents\WineList.txt",
"", "", False, 500, True)
Remarks
If showUI
is set to True
, a dialog box appears that shows the progress of the operation; the dialog box contains a Cancel button that can be used to cancel the operation. The dialog box is not modal, and therefore does not block user input to other windows in the program.
If the server does not respond within the specified connectionTimeout
, the operation is cancelled, and an exception is thrown.
DownloadFile
outputs trace information when you enable network tracing in your application. For more information, see Enabling Network Tracing.
Note
The DownloadFile
method does not send optional HTTP headers. Some servers may return 500 (Internal Server Error) if the optional user agent header is missing. To send optional headers, you must construct a request using the WebClient class.
Note
The FTP protocol sends information, including passwords, in plain text and should not be used for transmitting sensitive information.
The following table lists an example of a task involving the My.Computer.Network.DownloadFile
method.
To | See |
---|---|
Download a file | How to: Download a File |
See also
- Uri
- ICredentials
- Objects (Visual Basic)
- How to: Download a File in Visual Basic
- How to: Parse File Paths in Visual Basic
Applies to
DownloadFile(String, String, String, String, Boolean, Int32, Boolean, UICancelOption)
- Source:
- Network.vb
- Source:
- Network.vb
- Source:
- Network.vb
Downloads the specified remote file and saves it in the specified location.
public:
void DownloadFile(System::String ^ address, System::String ^ destinationFileName, System::String ^ userName, System::String ^ password, bool showUI, int connectionTimeout, bool overwrite, Microsoft::VisualBasic::FileIO::UICancelOption onUserCancel);
public void DownloadFile (string address, string destinationFileName, string userName, string password, bool showUI, int connectionTimeout, bool overwrite, Microsoft.VisualBasic.FileIO.UICancelOption onUserCancel);
member this.DownloadFile : string * string * string * string * bool * int * bool * Microsoft.VisualBasic.FileIO.UICancelOption -> unit
Public Sub DownloadFile (address As String, destinationFileName As String, userName As String, password As String, showUI As Boolean, connectionTimeout As Integer, overwrite As Boolean, onUserCancel As UICancelOption)
Parameters
- address
- String
Path of the file to download, including file name and host address.
- destinationFileName
- String
File name and path of the downloaded file.
- userName
- String
User name to authenticate. Default is an empty string, "".
- password
- String
Password to authenticate. Default is an empty string, "".
- showUI
- Boolean
True
to display the progress of the operation; otherwise False
. Default is False
.
- connectionTimeout
- Int32
Timeout interval, in milliseconds. Default is 100 seconds.
- overwrite
- Boolean
True
to overwrite existing files; otherwise False
. Default is False
.
- onUserCancel
- UICancelOption
Specifies behavior when the user clicks Cancel or No on the dialog box shown as a result of ShowUI
set to True
. Default is ThrowException.
Exceptions
destinationFileName
ends with a trailing slash.
overwrite
is set to False
and the destination file already exists.
The server does not respond within the specified connectionTimeout
.
User lacks necessary permissions to perform a network operation.
The request is denied by the target web server.
Examples
This example downloads the file WineList.txt
from http://www.cohowinery.com/downloads
and saves it to C:\Documents and Settings\All Users\Documents
.
My.Computer.Network.DownloadFile(
"http://www.cohowinery.com/downloads/WineList.txt",
"C:\Documents and Settings\All Users\Documents\WineList.txt")
This example downloads the file WineList.txt
from http://www.cohowinery.com/downloads
and saves it to C:\Documents and Settings\All Users\Documents
, specifying a timeout interval of 500 milliseconds.
My.Computer.Network.DownloadFile(
"http://www.cohowinery.com/downloads/",
"C:\Documents and Settings\All Users\Documents\WineList.txt",
"", "", False, 500, True)
Remarks
If showUI
is set to True
, a dialog box appears that shows the progress of the operation; the dialog box contains a Cancel button that can be used to cancel the operation. The dialog box is not modal, and therefore does not block user input to other windows in the program.
If the server does not respond within the specified connectionTimeout
, the operation is cancelled, and an exception is thrown.
DownloadFile
outputs trace information when you enable network tracing in your application. For more information, see Enabling Network Tracing.
Note
The DownloadFile
method does not send optional HTTP headers. Some servers may return 500 (Internal Server Error) if the optional user agent header is missing. To send optional headers, you must construct a request using the WebClient class.
Note
The FTP protocol sends information, including passwords, in plain text and should not be used for transmitting sensitive information.
The following table lists an example of a task involving the My.Computer.Network.DownloadFile
method.
To | See |
---|---|
Download a file | How to: Download a File |
See also
- Uri
- ICredentials
- Objects (Visual Basic)
- How to: Download a File in Visual Basic
- How to: Parse File Paths in Visual Basic
Applies to
DownloadFile(Uri, String, String, String, Boolean, Int32, Boolean, UICancelOption)
- Source:
- Network.vb
- Source:
- Network.vb
- Source:
- Network.vb
Downloads the specified remote file and saves it in the specified location.
public:
void DownloadFile(Uri ^ address, System::String ^ destinationFileName, System::String ^ userName, System::String ^ password, bool showUI, int connectionTimeout, bool overwrite, Microsoft::VisualBasic::FileIO::UICancelOption onUserCancel);
public void DownloadFile (Uri address, string destinationFileName, string userName, string password, bool showUI, int connectionTimeout, bool overwrite, Microsoft.VisualBasic.FileIO.UICancelOption onUserCancel);
member this.DownloadFile : Uri * string * string * string * bool * int * bool * Microsoft.VisualBasic.FileIO.UICancelOption -> unit
Public Sub DownloadFile (address As Uri, destinationFileName As String, userName As String, password As String, showUI As Boolean, connectionTimeout As Integer, overwrite As Boolean, onUserCancel As UICancelOption)
Parameters
- address
- Uri
Path of the file to download, including file name and host address.
- destinationFileName
- String
File name and path of the downloaded file.
- userName
- String
User name to authenticate. Default is an empty string, "".
- password
- String
Password to authenticate. Default is an empty string, "".
- showUI
- Boolean
True
to display the progress of the operation; otherwise False
. Default is False
.
- connectionTimeout
- Int32
Timeout interval, in milliseconds. Default is 100 seconds.
- overwrite
- Boolean
True
to overwrite existing files; otherwise False
. Default is False
.
- onUserCancel
- UICancelOption
Specifies behavior when the user clicks Cancel or No on the dialog box shown as a result of ShowUI
set to True
. Default is ThrowException.
Exceptions
destinationFileName
ends with a trailing slash.
overwrite
is set to False
and the destination file already exists.
The server does not respond within the specified connectionTimeout
.
User lacks necessary permissions to perform a network operation.
The request is denied by the target web server.
Examples
This example downloads the file WineList.txt
from http://www.cohowinery.com/downloads
and saves it to C:\Documents and Settings\All Users\Documents
.
My.Computer.Network.DownloadFile(
"http://www.cohowinery.com/downloads/WineList.txt",
"C:\Documents and Settings\All Users\Documents\WineList.txt")
This example downloads the file WineList.txt
from http://www.cohowinery.com/downloads
and saves it to C:\Documents and Settings\All Users\Documents
, specifying a timeout interval of 500 milliseconds.
My.Computer.Network.DownloadFile(
"http://www.cohowinery.com/downloads/",
"C:\Documents and Settings\All Users\Documents\WineList.txt",
"", "", False, 500, True)
Remarks
If showUI
is set to True
, a dialog box appears that shows the progress of the operation; the dialog box contains a Cancel button that can be used to cancel the operation. The dialog box is not modal, and therefore does not block user input to other windows in the program.
If the server does not respond within the specified connectionTimeout
, the operation is cancelled, and an exception is thrown.
DownloadFile
outputs trace information when you enable network tracing in your application. For more information, see Enabling Network Tracing.
Note
The DownloadFile
method does not send optional HTTP headers. Some servers may return 500 (Internal Server Error) if the optional user agent header is missing. To send optional headers, you must construct a request using the WebClient class.
Note
The FTP protocol sends information, including passwords, in plain text and should not be used for transmitting sensitive information.
The following table lists an example of a task involving the My.Computer.Network.DownloadFile
method.
To | See |
---|---|
Download a file | How to: Download a File |
See also
- Uri
- ICredentials
- Objects (Visual Basic)
- How to: Download a File in Visual Basic
- How to: Parse File Paths in Visual Basic