Network.DownloadFile 方法

定义

下载指定的远程文件并将其保存在指定位置。

重载

名称 说明
DownloadFile(String, String)

下载指定的远程文件并将其保存在指定位置。

DownloadFile(Uri, String)

下载指定的远程文件并将其保存在指定位置。

DownloadFile(String, String, String, String)

下载指定的远程文件并将其保存在指定位置。

DownloadFile(Uri, String, String, String)

下载指定的远程文件并将其保存在指定位置。

DownloadFile(Uri, String, ICredentials, Boolean, Int32, Boolean)

下载指定的远程文件并将其保存在指定位置。

DownloadFile(String, String, String, String, Boolean, Int32, Boolean)

下载指定的远程文件并将其保存在指定位置。

DownloadFile(Uri, String, ICredentials, Boolean, Int32, Boolean, UICancelOption)

下载指定的远程文件并将其保存在指定位置。

DownloadFile(Uri, String, String, String, Boolean, Int32, Boolean)

下载指定的远程文件并将其保存在指定位置。

DownloadFile(String, String, String, String, Boolean, Int32, Boolean, UICancelOption)

下载指定的远程文件并将其保存在指定位置。

DownloadFile(Uri, String, String, String, Boolean, Int32, Boolean, UICancelOption)

下载指定的远程文件并将其保存在指定位置。

DownloadFile(String, String)

下载指定的远程文件并将其保存在指定位置。

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)

参数

address
String

要下载的文件的路径,包括文件名和主机名。

destinationFileName
String

已下载文件的文件名和路径。

例外

destinationFileName 以尾部斜杠结尾。

服务器在默认超时(100 秒)内不响应。

用户缺少执行网络操作所需的权限。

目标 Web 服务器拒绝请求。

示例

此示例从http://www.cohowinery.com/downloads中下载文件WineList.txt并将其保存到 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")

此示例从http://www.cohowinery.com/downloads中下载文件WineList.txt并将其保存到C:\Documents and Settings\All Users\Documents其中,并指定超时间隔为 500 毫秒。

My.Computer.Network.DownloadFile(
  "http://www.cohowinery.com/downloads/", 
  "C:\Documents and Settings\All Users\Documents\WineList.txt", 
  "", "", False, 500, True)

注解

如果目标文件已存在,该方法 DownloadFile 将不会覆盖现有文件。 可以使用该方法的另一个重载 DownloadFile 来指示它覆盖现有文件、提供用户凭据或指定特定的超时值。

DownloadFile 在应用程序中启用网络跟踪时输出跟踪信息。 有关详细信息,请参阅 “启用网络跟踪”。

注释

该方法 DownloadFile 不发送可选的 HTTP 标头。 如果缺少可选的用户代理标头,某些服务器可能会返回 500(内部服务器错误)。 若要发送可选标头,必须使用类构造请求 WebClient

下表列出了涉及 My.Computer.Network.DownloadFile 该方法的任务的示例。

收件人 请参阅
下载文件 如何:下载文件

另请参阅

适用于

DownloadFile(Uri, String)

下载指定的远程文件并将其保存在指定位置。

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)

参数

address
Uri

要下载的文件的路径,包括文件名和主机名。

destinationFileName
String

已下载文件的文件名和路径。

例外

destinationFileName 以尾部斜杠结尾。

服务器在默认超时(100 秒)内不响应。

用户缺少执行网络操作所需的权限。

目标 Web 服务器拒绝请求。

示例

此示例从http://www.cohowinery.com/downloads中下载文件WineList.txt并将其保存到 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")

此示例从http://www.cohowinery.com/downloads中下载文件WineList.txt并将其保存到C:\Documents and Settings\All Users\Documents其中,并指定超时间隔为 500 毫秒。

My.Computer.Network.DownloadFile(
  "http://www.cohowinery.com/downloads/", 
  "C:\Documents and Settings\All Users\Documents\WineList.txt", 
  "", "", False, 500, True)

注解

如果目标文件已存在,该方法 DownloadFile 将不会覆盖现有文件。 可以使用该方法的另一个重载 DownloadFile 来指示它覆盖现有文件、提供用户凭据或指定特定的超时值。 DownloadFile 在应用程序中启用网络跟踪时输出跟踪信息。 有关详细信息,请参阅 “启用网络跟踪”。

注释

该方法 DownloadFile 不发送可选的 HTTP 标头。 如果缺少可选的用户代理标头,某些服务器可能会返回 500(内部服务器错误)。 若要发送可选标头,必须使用类构造请求 WebClient

下表列出了涉及 My.Computer.Network.DownloadFile 该方法的任务的示例。

收件人 请参阅
下载文件 如何:下载文件

另请参阅

适用于

DownloadFile(String, String, String, String)

下载指定的远程文件并将其保存在指定位置。

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)

参数

address
String

要下载的文件的路径,包括文件名和主机名。

destinationFileName
String

已下载文件的文件名和路径。

userName
String

要进行身份验证的用户名。 默认值为空字符串“”。

password
String

要进行身份验证的密码。 默认值为空字符串“”。

例外

destinationFileName 以尾部斜杠结尾。

服务器在默认超时(100 秒)内不响应。

用户缺少执行网络操作所需的权限。

目标 Web 服务器拒绝请求。

示例

此示例从http://www.cohowinery.com/downloads中下载文件WineList.txt并将其保存到 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")

此示例从http://www.cohowinery.com/downloads中下载文件WineList.txt并将其保存到C:\Documents and Settings\All Users\Documents其中,并指定超时间隔为 500 毫秒。

My.Computer.Network.DownloadFile(
  "http://www.cohowinery.com/downloads/", 
  "C:\Documents and Settings\All Users\Documents\WineList.txt", 
  "", "", False, 500, True)

注解

如果目标文件已存在,该方法 DownloadFile 将不会覆盖现有文件。 可以使用该方法的另一个重载 DownloadFile 来指示它覆盖现有文件或指定特定的超时值。

DownloadFile 在应用程序中启用网络跟踪时输出跟踪信息。 有关详细信息,请参阅 “启用网络跟踪”。

注释

该方法 DownloadFile 不发送可选的 HTTP 标头。 如果缺少可选的用户代理标头,某些服务器可能会返回 500(内部服务器错误)。 若要发送可选标头,必须使用类构造请求 WebClient

注释

FTP 协议以纯文本形式发送信息,包括密码,不应用于传输敏感信息。

下表列出了涉及 My.Computer.Network.DownloadFile 该方法的任务的示例。

收件人 请参阅
下载文件 如何:下载文件

另请参阅

适用于

DownloadFile(Uri, String, String, String)

下载指定的远程文件并将其保存在指定位置。

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)

参数

address
Uri

要下载的文件的路径,包括文件名和主机名。

destinationFileName
String

已下载文件的文件名和路径。

userName
String

要进行身份验证的用户名。 默认值为空字符串“”。

password
String

要进行身份验证的密码。 默认值为空字符串“”。

例外

destinationFileName 以尾部斜杠结尾。

服务器在默认超时(100 秒)内不响应。

用户缺少执行网络操作所需的权限。

目标 Web 服务器拒绝请求。

示例

此示例从http://www.cohowinery.com/downloads中下载文件WineList.txt并将其保存到 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")

此示例从http://www.cohowinery.com/downloads中下载文件WineList.txt并将其保存到C:\Documents and Settings\All Users\Documents其中,并指定超时间隔为 500 毫秒。

My.Computer.Network.DownloadFile(
  "http://www.cohowinery.com/downloads/", 
  "C:\Documents and Settings\All Users\Documents\WineList.txt", 
  "", "", False, 500, True)

注解

如果目标文件已存在,该方法 DownloadFile 将不会覆盖现有文件。 可以使用该方法的另一个重载 DownloadFile 来指示它覆盖现有文件或指定特定的超时值。

DownloadFile 在应用程序中启用网络跟踪时输出跟踪信息。 有关详细信息,请参阅 “启用网络跟踪”。

注释

该方法 DownloadFile 不发送可选的 HTTP 标头。 如果缺少可选的用户代理标头,某些服务器可能会返回 500(内部服务器错误)。 若要发送可选标头,必须使用类构造请求 WebClient

注释

FTP 协议以纯文本形式发送信息,包括密码,不应用于传输敏感信息。

下表列出了涉及 My.Computer.Network.DownloadFile 该方法的任务的示例。

收件人 请参阅
下载文件 如何:下载文件

另请参阅

适用于

DownloadFile(Uri, String, ICredentials, Boolean, Int32, Boolean)

下载指定的远程文件并将其保存在指定位置。

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)

参数

address
Uri

StringUri。 要下载的文件的路径,包括文件名和主机名。

destinationFileName
String

String。 已下载文件的文件名和路径。

networkCredentials
ICredentials

ICredentials。 要提供的凭据。

showUI
Boolean

True 显示操作的进度;否则 False。 默认值为 False

connectionTimeout
Int32

超时间隔(以毫秒为单位)。 默认值为 100 秒。

overwrite
Boolean

True 覆盖现有文件;否则 False。 默认值为 False

例外

destinationFileName 以尾部斜杠结尾。

overwrite 设置为 False 目标文件且目标文件已存在。

服务器未在指定的 connectionTimeout内响应。

用户缺少执行网络操作所需的权限。

目标 Web 服务器拒绝请求。

示例

此示例从http://www.cohowinery.com/downloads中下载文件WineList.txt并将其保存到 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")

此示例从http://www.cohowinery.com/downloads中下载文件WineList.txt并将其保存到C:\Documents and Settings\All Users\Documents其中,并指定超时间隔为 500 毫秒。

My.Computer.Network.DownloadFile(
  "http://www.cohowinery.com/downloads/", 
  "C:\Documents and Settings\All Users\Documents\WineList.txt", 
  "", "", False, 500, True)

注解

如果 showUI 设置为 True,将显示显示操作进度的对话框;该对话框包含可用于取消操作的 “取消 ”按钮。 对话框不是模式的,因此不会阻止用户输入到程序中的其他窗口。

如果服务器未在指定的 connectionTimeout范围内响应,则会取消该操作,并引发异常。

DownloadFile 在应用程序中启用网络跟踪时输出跟踪信息。 有关详细信息,请参阅 “启用网络跟踪”。

注释

该方法 DownloadFile 不发送可选的 HTTP 标头。 如果缺少可选的用户代理标头,某些服务器可能会返回 500(内部服务器错误)。 若要发送可选标头,必须使用类构造请求 WebClient

注释

FTP 协议以纯文本形式发送信息,包括密码,不应用于传输敏感信息。

下表列出了涉及 My.Computer.Network.DownloadFile 该方法的任务的示例。

收件人 请参阅
下载文件 如何:下载文件

另请参阅

适用于

DownloadFile(String, String, String, String, Boolean, Int32, Boolean)

下载指定的远程文件并将其保存在指定位置。

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)

参数

address
String

要下载的文件的路径,包括文件名和主机名。

destinationFileName
String

已下载文件的文件名和路径。

userName
String

要进行身份验证的用户名。 默认值为空字符串“”。

password
String

要进行身份验证的密码。 默认值为空字符串“”。

showUI
Boolean

True 显示操作的进度;否则 False。 默认值为 False

connectionTimeout
Int32

Int32。 超时间隔(以毫秒为单位)。 默认值为 100 秒。

overwrite
Boolean

True 覆盖现有文件;否则 False。 默认值为 False

例外

destinationFileName 以尾部斜杠结尾。

overwrite 设置为 False 目标文件且目标文件已存在。

服务器未在指定的 connectionTimeout内响应。

用户缺少执行网络操作所需的权限。

目标 Web 服务器拒绝请求。

示例

此示例从http://www.cohowinery.com/downloads中下载文件WineList.txt并将其保存到 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")

此示例从http://www.cohowinery.com/downloads中下载文件WineList.txt并将其保存到C:\Documents and Settings\All Users\Documents其中,并指定超时间隔为 500 毫秒。

My.Computer.Network.DownloadFile(
  "http://www.cohowinery.com/downloads/", 
  "C:\Documents and Settings\All Users\Documents\WineList.txt", 
  "", "", False, 500, True)

注解

如果 showUI 设置为 True,将显示显示操作进度的对话框;该对话框包含可用于取消操作的 “取消 ”按钮。 对话框不是模式的,因此不会阻止用户输入到程序中的其他窗口。

如果服务器未在指定的 connectionTimeout范围内响应,则会取消该操作,并引发异常。

DownloadFile 在应用程序中启用网络跟踪时输出跟踪信息。 有关详细信息,请参阅 “启用网络跟踪”。

注释

该方法 DownloadFile 不发送可选的 HTTP 标头。 如果缺少可选的用户代理标头,某些服务器可能会返回 500(内部服务器错误)。 若要发送可选标头,必须使用类构造请求 WebClient

注释

FTP 协议以纯文本形式发送信息,包括密码,不应用于传输敏感信息。

下表列出了涉及 My.Computer.Network.DownloadFile 该方法的任务的示例。

收件人 请参阅
下载文件 如何:下载文件

另请参阅

适用于

DownloadFile(Uri, String, ICredentials, Boolean, Int32, Boolean, UICancelOption)

下载指定的远程文件并将其保存在指定位置。

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)

参数

address
Uri

要下载的文件的路径,包括文件名和主机名。

destinationFileName
String

已下载文件的文件名和路径。

networkCredentials
ICredentials

要提供的凭据。

showUI
Boolean

True 显示操作的进度;否则 False。 默认值为 False

connectionTimeout
Int32

超时间隔(以毫秒为单位)。 默认值为 100 秒。

overwrite
Boolean

True 覆盖现有文件;否则 False。 默认值为 False

onUserCancel
UICancelOption

指定当用户单击“取消”或“”时的行为,该对话框显示为设置为 < a0/> 的结果。 默认值为 ThrowException

例外

destinationFileName 以尾部斜杠结尾。

overwrite 设置为 False 目标文件且目标文件已存在。

服务器未在指定的 connectionTimeout内响应。

用户缺少执行网络操作所需的权限。

目标 Web 服务器拒绝请求。

示例

此示例从http://www.cohowinery.com/downloads中下载文件WineList.txt并将其保存到 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")

此示例从http://www.cohowinery.com/downloads中下载文件WineList.txt并将其保存到C:\Documents and Settings\All Users\Documents其中,并指定超时间隔为 500 毫秒。

My.Computer.Network.DownloadFile(
  "http://www.cohowinery.com/downloads/", 
  "C:\Documents and Settings\All Users\Documents\WineList.txt", 
  "", "", False, 500, True)

注解

如果 showUI 设置为 True,将显示显示操作进度的对话框;该对话框包含可用于取消操作的 “取消 ”按钮。 对话框不是模式的,因此不会阻止用户输入到程序中的其他窗口。

如果服务器未在指定的 connectionTimeout范围内响应,则会取消该操作,并引发异常。

DownloadFile 在应用程序中启用网络跟踪时输出跟踪信息。 有关详细信息,请参阅 “启用网络跟踪”。

注释

该方法 DownloadFile 不发送可选的 HTTP 标头。 如果缺少可选的用户代理标头,某些服务器可能会返回 500(内部服务器错误)。 若要发送可选标头,必须使用类构造请求 WebClient

注释

FTP 协议以纯文本形式发送信息,包括密码,不应用于传输敏感信息。

下表列出了涉及 My.Computer.Network.DownloadFile 该方法的任务的示例。

收件人 请参阅
下载文件 如何:下载文件

另请参阅

适用于

DownloadFile(Uri, String, String, String, Boolean, Int32, Boolean)

下载指定的远程文件并将其保存在指定位置。

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)

参数

address
Uri

要下载的文件的路径,包括文件名和主机名。

destinationFileName
String

已下载文件的文件名和路径。

userName
String

要进行身份验证的用户名。 默认值为空字符串“”。

password
String

要进行身份验证的密码。 默认值为空字符串“”。

showUI
Boolean

True 显示操作的进度;否则 False。 默认值为 False

connectionTimeout
Int32

超时间隔(以毫秒为单位)。 默认值为 100 秒。

overwrite
Boolean

True 覆盖现有文件;否则 False。 默认值为 False

例外

destinationFileName 以尾部斜杠结尾。

overwrite 设置为 False 目标文件且目标文件已存在。

服务器未在指定的 connectionTimeout内响应。

用户缺少执行网络操作所需的权限。

目标 Web 服务器拒绝请求。

示例

此示例从http://www.cohowinery.com/downloads中下载文件WineList.txt并将其保存到 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")

此示例从http://www.cohowinery.com/downloads中下载文件WineList.txt并将其保存到C:\Documents and Settings\All Users\Documents其中,并指定超时间隔为 500 毫秒。

My.Computer.Network.DownloadFile(
  "http://www.cohowinery.com/downloads/", 
  "C:\Documents and Settings\All Users\Documents\WineList.txt", 
  "", "", False, 500, True)

注解

如果 showUI 设置为 True,将显示显示操作进度的对话框;该对话框包含可用于取消操作的 “取消 ”按钮。 对话框不是模式的,因此不会阻止用户输入到程序中的其他窗口。

如果服务器未在指定的 connectionTimeout范围内响应,则会取消该操作,并引发异常。

DownloadFile 在应用程序中启用网络跟踪时输出跟踪信息。 有关详细信息,请参阅 “启用网络跟踪”。

注释

该方法 DownloadFile 不发送可选的 HTTP 标头。 如果缺少可选的用户代理标头,某些服务器可能会返回 500(内部服务器错误)。 若要发送可选标头,必须使用类构造请求 WebClient

注释

FTP 协议以纯文本形式发送信息,包括密码,不应用于传输敏感信息。

下表列出了涉及 My.Computer.Network.DownloadFile 该方法的任务的示例。

收件人 请参阅
下载文件 如何:下载文件

另请参阅

适用于

DownloadFile(String, String, String, String, Boolean, Int32, Boolean, UICancelOption)

下载指定的远程文件并将其保存在指定位置。

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)

参数

address
String

要下载的文件的路径,包括文件名和主机名。

destinationFileName
String

已下载文件的文件名和路径。

userName
String

要进行身份验证的用户名。 默认值为空字符串“”。

password
String

要进行身份验证的密码。 默认值为空字符串“”。

showUI
Boolean

True 显示操作的进度;否则 False。 默认值为 False

connectionTimeout
Int32

超时间隔(以毫秒为单位)。 默认值为 100 秒。

overwrite
Boolean

True 覆盖现有文件;否则 False。 默认值为 False

onUserCancel
UICancelOption

指定当用户单击“取消”或“”时的行为,该对话框显示为设置为 < a0/> 的结果。 默认值为 ThrowException

例外

destinationFileName 以尾部斜杠结尾。

overwrite 设置为 False 目标文件且目标文件已存在。

服务器未在指定的 connectionTimeout内响应。

用户缺少执行网络操作所需的权限。

目标 Web 服务器拒绝请求。

示例

此示例从http://www.cohowinery.com/downloads中下载文件WineList.txt并将其保存到 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")

此示例从http://www.cohowinery.com/downloads中下载文件WineList.txt并将其保存到C:\Documents and Settings\All Users\Documents其中,并指定超时间隔为 500 毫秒。

My.Computer.Network.DownloadFile(
  "http://www.cohowinery.com/downloads/", 
  "C:\Documents and Settings\All Users\Documents\WineList.txt", 
  "", "", False, 500, True)

注解

如果 showUI 设置为 True,将显示显示操作进度的对话框;该对话框包含可用于取消操作的 “取消 ”按钮。 对话框不是模式的,因此不会阻止用户输入到程序中的其他窗口。

如果服务器未在指定的 connectionTimeout范围内响应,则会取消该操作,并引发异常。

DownloadFile 在应用程序中启用网络跟踪时输出跟踪信息。 有关详细信息,请参阅 “启用网络跟踪”。

注释

该方法 DownloadFile 不发送可选的 HTTP 标头。 如果缺少可选的用户代理标头,某些服务器可能会返回 500(内部服务器错误)。 若要发送可选标头,必须使用类构造请求 WebClient

注释

FTP 协议以纯文本形式发送信息,包括密码,不应用于传输敏感信息。

下表列出了涉及 My.Computer.Network.DownloadFile 该方法的任务的示例。

收件人 请参阅
下载文件 如何:下载文件

另请参阅

适用于

DownloadFile(Uri, String, String, String, Boolean, Int32, Boolean, UICancelOption)

下载指定的远程文件并将其保存在指定位置。

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)

参数

address
Uri

要下载的文件的路径,包括文件名和主机名。

destinationFileName
String

已下载文件的文件名和路径。

userName
String

要进行身份验证的用户名。 默认值为空字符串“”。

password
String

要进行身份验证的密码。 默认值为空字符串“”。

showUI
Boolean

True 显示操作的进度;否则 False。 默认值为 False

connectionTimeout
Int32

超时间隔(以毫秒为单位)。 默认值为 100 秒。

overwrite
Boolean

True 覆盖现有文件;否则 False。 默认值为 False

onUserCancel
UICancelOption

指定当用户单击“取消”或“”时的行为,该对话框显示为设置为 < a0/> 的结果。 默认值为 ThrowException

例外

destinationFileName 以尾部斜杠结尾。

overwrite 设置为 False 目标文件且目标文件已存在。

服务器未在指定的 connectionTimeout内响应。

用户缺少执行网络操作所需的权限。

目标 Web 服务器拒绝请求。

示例

此示例从http://www.cohowinery.com/downloads中下载文件WineList.txt并将其保存到 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")

此示例从http://www.cohowinery.com/downloads中下载文件WineList.txt并将其保存到C:\Documents and Settings\All Users\Documents其中,并指定超时间隔为 500 毫秒。

My.Computer.Network.DownloadFile(
  "http://www.cohowinery.com/downloads/", 
  "C:\Documents and Settings\All Users\Documents\WineList.txt", 
  "", "", False, 500, True)

注解

如果 showUI 设置为 True,将显示显示操作进度的对话框;该对话框包含可用于取消操作的 “取消 ”按钮。 对话框不是模式的,因此不会阻止用户输入到程序中的其他窗口。

如果服务器未在指定的 connectionTimeout范围内响应,则会取消该操作,并引发异常。

DownloadFile 在应用程序中启用网络跟踪时输出跟踪信息。 有关详细信息,请参阅 “启用网络跟踪”。

注释

该方法 DownloadFile 不发送可选的 HTTP 标头。 如果缺少可选的用户代理标头,某些服务器可能会返回 500(内部服务器错误)。 若要发送可选标头,必须使用类构造请求 WebClient

注释

FTP 协议以纯文本形式发送信息,包括密码,不应用于传输敏感信息。

下表列出了涉及 My.Computer.Network.DownloadFile 该方法的任务的示例。

收件人 请参阅
下载文件 如何:下载文件

另请参阅

适用于