'c# filedownload'에 해당되는 글 1건

  1. 2015.06.09 C# WebClient로 파일 다운 로드가 안될때

C# WebClient FileDownLoad 에러 해결



using System;
using System.ComponentModel;
using System.Net;
 
namespace WebClient_FileDownLoad
{
   class ClientDownLoadFile
   {
      static void Main( string[] args )
      {
         // 서버측에서 알 수 없는 헤더 Agent로 인해서 정상적인 파일다운 불가
         WebClient webClient = new WebClient();
         webClient.DownloadFileCompleted += new AsyncCompletedEventHandler( FileDownLoadCompleted );
 
         // 익스플로러의 헤더 에이전트 추가해서 문제 해결
         webClient.Headers.Add( "User-Agent",
            "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.3; WOW64; Trident/7.0)" );
 
         string sUrl = "파일 다운로드 주소";
 
         webClient.DownloadFileAsync( new Uri( sUrl ), "다운파일 이름" );
 
         Console.ReadLine();
      }
 
      static void FileDownLoadCompleted( object sender, AsyncCompletedEventArgs e )
      {
         Console.WriteLine( "DownLoad Finished...." );
      }
   }
}




Posted by seanpaul
,