2017-01-24 1 views
0

나는 Windows phone 프로젝트를하고 있으며, 인터넷에서 텍스트 파일을 다운로드하고 그 내용을 읽을 필요가 있습니다.Windows phone 8.1의 google 드라이브에서 txt 파일을 다운로드하십시오.

private async Task pobierz() 
{ 
    string source = "https://drive.google.com/file/d/0BzgKBwKyU4oORkxxSlVITGswb1E/view?usp=sharing"; 
    string LocalName = "hej.txt"; 
    var srce = new Uri(source, UriKind.Absolute); 
    // var destinationFile =await KnownFolders.PicturesLibrary.CreateFileAsync() 
    StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(new Uri(@"ms-appx:///Assets/hej.txt")); 

    var downloader = new BackgroundDownloader(); 
    DownloadOperation download = downloader.CreateDownload(srce,file); 
} 
+2

이 아마도 당신이 "가 작동하지 않았다"어떻게 설명 할 수 있습니까? –

+0

좀 더 설명해 주시겠습니까? –

+0

내 프로그램이 잘 debbuging 아무 예외도 표시되지 않습니다 :/ – Witcherek

답변

0

BackgroundDownloader을 사용하는 방법에 대한 자세한 설명은 https://msdn.microsoft.com/en-us/library/windows/apps/xaml/jj152726.aspx?f=255&MSPPError=-2147217396을 참조하십시오

이 내가 시도 것입니다 (그러나 그것은 작동하지 않았다).

다음과 같은 방법을 구현하고 호출 할 필요가

:

private async void HandleDownloadAsync(DownloadOperation download, bool start) 
{ 
    try 
    { 
     // Store the download so we can pause/resume. 
     activeDownloads.Add(download); 

     Progress<DownloadOperation> progressCallback = new Progress<DownloadOperation>(DownloadProgress); 
     if (start) 
     { 
      // Start the download and attach a progress handler. 
      await download.StartAsync().AsTask(cts.Token, progressCallback); 
     } 
     else 
     { 
      // The download was already running when the application started, re-attach the progress handler. 
      await download.AttachAsync().AsTask(cts.Token, progressCallback); 
     } 

     ResponseInformation response = download.GetResponseInformation(); 
     Log(String.Format("Completed: {0}, Status Code: {1}", download.Guid, response.StatusCode)); 
    } 
    catch (TaskCanceledException) 
    { 
     Log("Download cancelled."); 
    } 
    catch (Exception ex) 
    { 
     LogException("Error", ex); 
    } 
    finally 
    { 
     activeDownloads.Remove(download); 
    } 
} 
+0

내가 사용할 수 없습니다 HandleDownloadAsync 메서드 :/이름은 현재 컨텍스트에 존재하지 않습니다 – Witcherek

+0

죄송합니다, 빨리 대답. 해결책을 찾았습니다. 내 대답을 편집 할 것입니다. – SirBirne

+0

okok 내 친구가 기다릴 것입니다. D – Witcherek

관련 문제