2014-03-29 2 views
0

매 시간마다 웹 응용 프로그램이 주어진 URL에서 파일을 다운로드 할 수있게하는 기능을 만들고 싶습니다. - C에서 주어진 URL의 파일 다운로드

  • 그런 다음 압축을 풀고 코드
  • 하여 해당 파일을 추출 특정에 해당 파일을 넣어

    그것은 주어진 URL로 이동
    1. , zip 파일 (http://www.abc.com/FileFolder/GetUrFile.aspx?username=abc&password=000&filename=abc.zip 등)를 다운로드 :

      은 다음과 같이이어야한다 폴더

    2. 이 과정을 반복마다 1 ~ 2 시간 후에

    당신을 하라구요,,램 비나이 쿠마르

  • 답변

    1

    귀하의 솔루션은 3 단계에있을 것입니다 : URL에서

    1. 파일 다운로드
    가지고 System.Net.WebClient

    using (WebClient Client = new WebClient()) 
    { 
        Client.DownloadFile("http://www.abc.com/file/song/a.mpeg", "a.mpeg"); 
    } 
    


    2. 압축을 풀고 봐 파일
    .Net 4.5의 경우 System.IO.Compression.ZipFile에서 볼 수 있습니다.

    string startPath = @"c:\example\start"; 
    string zipPath = @"c:\example\result.zip"; 
    string extractPath = @"c:\example\extract"; 
    
    ZipFile.CreateFromDirectory(startPath, zipPath); 
    ZipFile.ExtractToDirectory(zipPath, extractPath); 
    


    아니면 더 강력한 솔루션은 압축을 해제하려면 아마 SharpZipLib 들여다

    3. 스케줄러
    당신이 System.Timers 볼 수 ;

    public void MyMethod() 
        { 
         Timer timer = new Timer(); 
         timer.Interval = new TimeSpan(0, 15, 0).TotalMilliseconds; 
         timer.AutoReset = true; 
         timer.Elapsed += new ElapsedEventHandler(Timer_Elapsed); 
         timer.Enabled = true; 
        } 
    
        public void Timer_Elapsed(object sender, ElapsedEventArgs e) 
        { 
         //Do your stuff here 
        } 
    

    이들을 결합하고 솔루션을 코딩하십시오.

    +0

    빠른 응답을 위해 Loki에게 감사드립니다 .... – ShubhVinay

    +0

    @ Loki- CreateFromDirectory (startPath, zipPath); 및 ExtractToDirectory (zipPath, extractPath); 당신이이 일을하도록 안내 한 방법. – ShubhVinay

    +0

    @ShubhVinay 'System.IO.Compression.FileSystem'에 대한 참조를 추가해야합니다. 그런 다음 라이브러리에'using System.IO.Compression'을 포함시키고 ZipFile.CreateFromDirectory 또는 ZipFile.ExtractToDirectory를 호출하십시오. – Loki

    관련 문제