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 伺服器拒絕該要求。

範例

此範例會從 下載檔案WineList.txt,並將其儲存至 C:\Documents and Settings\All Users\Documentshttp://www.cohowinery.com/downloads

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 伺服器拒絕該要求。

範例

此範例會從 下載檔案WineList.txt,並將其儲存至 C:\Documents and Settings\All Users\Documentshttp://www.cohowinery.com/downloads

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 伺服器拒絕該要求。

範例

此範例會從 下載檔案WineList.txt,並將其儲存至 C:\Documents and Settings\All Users\Documentshttp://www.cohowinery.com/downloads

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 伺服器拒絕該要求。

範例

此範例會從 下載檔案WineList.txt,並將它儲存至 C:\Documents and Settings\All Users\Documentshttp://www.cohowinery.com/downloads

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 伺服器拒絕該要求。

範例

此範例會從 下載檔案WineList.txt,並將它儲存至 C:\Documents and Settings\All Users\Documentshttp://www.cohowinery.com/downloads

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 伺服器拒絕該要求。

範例

此範例會從 下載檔案WineList.txt,並將它儲存至 C:\Documents and Settings\All Users\Documentshttp://www.cohowinery.com/downloads

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

指定當 showUI 設為 True 時,使用者在顯示的對話方塊上按一下 [取消] 或 [否] 後會產生的行為。 預設為 ThrowException

例外狀況

destinationFileName 以斜線結束。

overwrite 設定為 False,而且目的檔案已經存在。

伺服器沒有在指定的 connectionTimeout 內回應。

使用者缺乏執行網路作業的必要權限。

目標 Web 伺服器拒絕該要求。

範例

此範例會從 下載檔案WineList.txt,並將它儲存至 C:\Documents and Settings\All Users\Documentshttp://www.cohowinery.com/downloads

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 伺服器拒絕該要求。

範例

此範例會從 下載檔案WineList.txt,並將它儲存至 C:\Documents and Settings\All Users\Documentshttp://www.cohowinery.com/downloads

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

指定當 ShowUI 設為 True 時,使用者在顯示的對話方塊上按一下 [取消] 或 [否] 後會產生的行為。 預設為 ThrowException

例外狀況

destinationFileName 以斜線結束。

overwrite 設定為 False,而且目的檔案已經存在。

伺服器沒有在指定的 connectionTimeout 內回應。

使用者缺乏執行網路作業的必要權限。

目標 Web 伺服器拒絕該要求。

範例

此範例會從 下載檔案WineList.txt,並將它儲存至 C:\Documents and Settings\All Users\Documentshttp://www.cohowinery.com/downloads

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

指定當 ShowUI 設為 True 時,使用者在顯示的對話方塊上按一下 [取消] 或 [否] 後會產生的行為。 預設為 ThrowException

例外狀況

destinationFileName 以斜線結束。

overwrite 設定為 False,而且目的檔案已經存在。

伺服器沒有在指定的 connectionTimeout 內回應。

使用者缺乏執行網路作業的必要權限。

目標 Web 伺服器拒絕該要求。

範例

此範例會從 下載檔案WineList.txt,並將其儲存至 C:\Documents and Settings\All Users\Documentshttp://www.cohowinery.com/downloads

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 方法的工作範例。

收件者 請參閱
下載檔案 作法:下載檔案

另請參閱

適用於