Network.DownloadFile 方法

定義

下載指定的遠端檔案並儲存在指定位置。

多載

名稱 Description
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 秒)內回應。

使用者缺乏執行網路操作所需的權限。

該請求被目標網頁伺服器拒絕。

範例

這個範例是WineList.txthttp://www.cohowinery.com/downloads從 下載檔案並儲存到 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")

此範例從 WineList.txthttp://www.cohowinery.com/downloads 下載檔案並儲存至 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 秒)內回應。

使用者缺乏執行網路操作所需的權限。

該請求被目標網頁伺服器拒絕。

範例

這個範例是WineList.txthttp://www.cohowinery.com/downloads從 下載檔案並儲存到 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")

此範例從 WineList.txthttp://www.cohowinery.com/downloads 下載檔案並儲存至 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 秒)內回應。

使用者缺乏執行網路操作所需的權限。

該請求被目標網頁伺服器拒絕。

範例

這個範例是WineList.txthttp://www.cohowinery.com/downloads從 下載檔案並儲存到 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")

此範例從 WineList.txthttp://www.cohowinery.com/downloads 下載檔案並儲存至 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 秒)內回應。

使用者缺乏執行網路操作所需的權限。

該請求被目標網頁伺服器拒絕。

範例

這個範例是WineList.txthttp://www.cohowinery.com/downloads從 下載檔案並儲存到 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")

此範例從 WineList.txthttp://www.cohowinery.com/downloads 下載檔案並儲存至 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範圍內回應。

使用者缺乏執行網路操作所需的權限。

該請求被目標網頁伺服器拒絕。

範例

這個範例是WineList.txthttp://www.cohowinery.com/downloads從 下載檔案並儲存到 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")

此範例從 WineList.txthttp://www.cohowinery.com/downloads 下載檔案並儲存至 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範圍內回應。

使用者缺乏執行網路操作所需的權限。

該請求被目標網頁伺服器拒絕。

範例

這個範例是WineList.txthttp://www.cohowinery.com/downloads從 下載檔案並儲存到 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")

此範例從 WineList.txthttp://www.cohowinery.com/downloads 下載檔案並儲存至 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

當使用者在設定為 True的對話showUI框中點擊取消時,指定行為。 預設值為 ThrowException

例外狀況

destinationFileName 以尾部斜斬結尾。

overwrite 設定為 , False 且目標檔案已存在。

伺服器不會在指定的 connectionTimeout範圍內回應。

使用者缺乏執行網路操作所需的權限。

該請求被目標網頁伺服器拒絕。

範例

這個範例是WineList.txthttp://www.cohowinery.com/downloads從 下載檔案並儲存到 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")

此範例從 WineList.txthttp://www.cohowinery.com/downloads 下載檔案並儲存至 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範圍內回應。

使用者缺乏執行網路操作所需的權限。

該請求被目標網頁伺服器拒絕。

範例

這個範例是WineList.txthttp://www.cohowinery.com/downloads從 下載檔案並儲存到 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")

此範例從 WineList.txthttp://www.cohowinery.com/downloads 下載檔案並儲存至 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

當使用者在設定為 True的對話ShowUI框中點擊取消時,指定行為。 預設值為 ThrowException

例外狀況

destinationFileName 以尾部斜斬結尾。

overwrite 設定為 , False 且目標檔案已存在。

伺服器不會在指定的 connectionTimeout範圍內回應。

使用者缺乏執行網路操作所需的權限。

該請求被目標網頁伺服器拒絕。

範例

這個範例是WineList.txthttp://www.cohowinery.com/downloads從 下載檔案並儲存到 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")

此範例從 WineList.txthttp://www.cohowinery.com/downloads 下載檔案並儲存至 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

當使用者在設定為 True的對話ShowUI框中點擊取消時,指定行為。 預設值為 ThrowException

例外狀況

destinationFileName 以尾部斜斬結尾。

overwrite 設定為 , False 且目標檔案已存在。

伺服器不會在指定的 connectionTimeout範圍內回應。

使用者缺乏執行網路操作所需的權限。

該請求被目標網頁伺服器拒絕。

範例

這個範例是WineList.txthttp://www.cohowinery.com/downloads從 下載檔案並儲存到 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")

此範例從 WineList.txthttp://www.cohowinery.com/downloads 下載檔案並儲存至 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 方法的任務範例。

看!
下載檔案 如何:下載檔案

另請參閱

適用於