WebClient.DownloadFile 메서드

정의

지정된 URI를 사용하여 로컬 파일에 리소스를 다운로드합니다.

오버로드

DownloadFile(Uri, String)

지정된 URI를 사용하여 로컬 파일에 리소스를 다운로드합니다.

DownloadFile(String, String)

지정된 URI를 사용하여 로컬 파일에 리소스를 다운로드합니다.

DownloadFile(Uri, String)

Source:
WebClient.cs
Source:
WebClient.cs
Source:
WebClient.cs

지정된 URI를 사용하여 로컬 파일에 리소스를 다운로드합니다.

public:
 void DownloadFile(Uri ^ address, System::String ^ fileName);
public void DownloadFile (Uri address, string fileName);
member this.DownloadFile : Uri * string -> unit
Public Sub DownloadFile (address As Uri, fileName As String)

매개 변수

address
Uri

String으로 지정된 URI입니다. 여기서 데이터를 다운로드합니다.

fileName
String

데이터를 받을 로컬 파일의 이름입니다.

예외

address 매개 변수가 null인 경우

또는

fileName 매개 변수가 null인 경우

BaseAddressaddress를 조합하여 만든 URI가 잘못된 경우

또는

filenamenull 또는 Empty입니다.

또는

파일이 없습니다.

또는

데이터를 다운로드하는 동안 오류가 발생한 경우

메서드가 여러 스레드에서 동시에 호출된 경우

설명

메서드는 DownloadFile 매개 변수에서 에 지정된 URI에서 로컬 파일 데이터로 address 다운로드합니다. 이 메서드는 리소스를 다운로드하는 동안 차단합니다. 리소스를 다운로드하고 서버의 응답을 기다리는 동안 계속 실행하려면 메서드 중 DownloadFileAsync 하나를 사용합니다.

속성이 BaseAddress 빈 문자열("")이 아니고 address 절대 URI를 포함하지 않는 경우 는 요청된 데이터의 절대 URI address 를 형성하기 위해 와 BaseAddress 결합된 상대 URI여야 합니다. 속성이 QueryString 빈 문자열이 아니면 에 추가됩니다 address.

이 메서드는 RETR 명령을 사용하여 FTP 리소스를 다운로드합니다. HTTP 리소스의 경우 GET 메서드가 사용됩니다.

참고

애플리케이션에 네트워크 추적을 사용하도록 설정하면 이 멤버에서 추적 정보를 출력합니다. 자세한 내용은 .NET Framework 네트워크 추적을 참조하세요.

ASP.NET 페이지와 같은 중간 계층 애플리케이션에서는이 메서드를 사용 하는 경우 애플리케이션을 실행 중인 계정에 파일에 액세스할 수 있는 권한이 없는 경우는 오류가 나타납니다.

적용 대상

DownloadFile(String, String)

Source:
WebClient.cs
Source:
WebClient.cs
Source:
WebClient.cs

지정된 URI를 사용하여 로컬 파일에 리소스를 다운로드합니다.

public:
 void DownloadFile(System::String ^ address, System::String ^ fileName);
public void DownloadFile (string address, string fileName);
member this.DownloadFile : string * string -> unit
Public Sub DownloadFile (address As String, fileName As String)

매개 변수

address
String

데이터를 다운로드할 URI입니다.

fileName
String

데이터를 받을 로컬 파일의 이름입니다.

예외

address 매개 변수가 null인 경우

BaseAddressaddress를 조합하여 만든 URI가 잘못된 경우

또는

filenamenull 또는 Empty입니다.

또는

파일이 없습니다.

또는 데이터를 다운로드하는 동안 오류가 발생한 경우

메서드가 여러 스레드에서 동시에 호출된 경우

예제

다음 코드 예제에서는 에서 로컬 하드 드라이브로 파일을 http://www.contoso.com 다운로드합니다.

String^ remoteUri = "http://www.contoso.com/library/homepage/images/";
String^ fileName = "ms-banner.gif", ^myStringWebResource = nullptr;
// Create a new WebClient instance.
WebClient^ myWebClient = gcnew WebClient;
// Concatenate the domain with the Web resource filename.
myStringWebResource = String::Concat( remoteUri, fileName );
Console::WriteLine( "Downloading File \"{0}\" from \"{1}\" .......\n\n", fileName, myStringWebResource );
// Download the Web resource and save it into the current filesystem folder.
myWebClient->DownloadFile( myStringWebResource, fileName );
Console::WriteLine( "Successfully Downloaded File \"{0}\" from \"{1}\"", fileName, myStringWebResource );
Console::WriteLine( "\nDownloaded file saved in the following file system folder:\n\t {0}", Application::StartupPath );
string remoteUri = "http://www.contoso.com/library/homepage/images/";
string fileName = "ms-banner.gif", myStringWebResource = null;
// Create a new WebClient instance.
WebClient myWebClient = new WebClient();
// Concatenate the domain with the Web resource filename.
myStringWebResource = remoteUri + fileName;
Console.WriteLine("Downloading File \"{0}\" from \"{1}\" .......\n\n", fileName, myStringWebResource);
// Download the Web resource and save it into the current filesystem folder.
myWebClient.DownloadFile(myStringWebResource,fileName);		
Console.WriteLine("Successfully Downloaded File \"{0}\" from \"{1}\"", fileName, myStringWebResource);
Console.WriteLine("\nDownloaded file saved in the following file system folder:\n\t" + Application.StartupPath);
Dim remoteUri As String = "http://www.contoso.com/library/homepage/images/"
Dim fileName As String = "ms-banner.gif"
Dim myStringWebResource As String = Nothing
' Create a new WebClient instance.
Dim myWebClient As New WebClient()
' Concatenate the domain with the Web resource filename. Because DownloadFile 
'requires a fully qualified resource name, concatenate the domain with the Web resource file name.
myStringWebResource = remoteUri + fileName
Console.WriteLine("Downloading File ""{0}"" from ""{1}"" ......." + ControlChars.Cr + ControlChars.Cr, fileName, myStringWebResource)
' The DownloadFile() method downloads the Web resource and saves it into the current file-system folder.
myWebClient.DownloadFile(myStringWebResource, fileName)
Console.WriteLine("Successfully Downloaded file ""{0}"" from ""{1}""", fileName, myStringWebResource)
Console.WriteLine((ControlChars.Cr + "Downloaded file saved in the following file system folder:" + ControlChars.Cr + ControlChars.Tab + Application.StartupPath))

설명

메서드는 DownloadFile 매개 변수에서 에 지정된 URI에서 로컬 파일 데이터로 address 다운로드합니다. 이 메서드는 리소스를 다운로드하는 동안 차단합니다. 리소스를 다운로드하고 서버의 응답을 기다리는 동안 계속 실행하려면 메서드 중 DownloadFileAsync 하나를 사용합니다.

속성이 BaseAddress 빈 문자열("")이 아니고 address 절대 URI를 포함하지 않는 경우 는 요청된 데이터의 절대 URI address 를 형성하기 위해 와 BaseAddress 결합된 상대 URI여야 합니다. 속성이 QueryString 빈 문자열이 아니면 에 추가됩니다 address.

이 메서드는 RETR 명령을 사용하여 FTP 리소스를 다운로드합니다. HTTP 리소스의 경우 GET 메서드가 사용됩니다.

참고

애플리케이션에 네트워크 추적을 사용하도록 설정하면 이 멤버에서 추적 정보를 출력합니다. 자세한 내용은 .NET Framework 네트워크 추적을 참조하세요.

ASP.NET 페이지와 같은 중간 계층 애플리케이션에서는이 메서드를 사용 하는 경우 애플리케이션을 실행 중인 계정에 파일에 액세스할 수 있는 권한이 없는 경우는 오류가 나타납니다.

적용 대상