2011-08-11 68 views

回答

1

您可以下載這些文件並將它們複製到獨立存儲。

事情是這樣的......

 private void DownloadFiles() 
    { 
     var wc = new WebClient(); 
     wc.OpenReadCompleted += WcOpenReadCompleted; 
     wc.OpenReadAsync(new Uri("http://myserver/myfile.file", UriKind.Absolute)); 
    } 

    public static void CopyStream(Stream input, Stream output) 
    { 
     var buffer = new byte[32768]; 
     while (true) 
     { 
      int read = input.Read(buffer, 0, buffer.Length); 
      if (read <= 0) 
       return; 

      output.Write(buffer, 0, read); 
     } 
    } 

    private static void WcOpenReadCompleted(object sender, OpenReadCompletedEventArgs e) 
    { 
     using (IsolatedStorageFile userStoreForApplication = IsolatedStorageFile.GetUserStoreForApplication()) 
     { 
      var isolatedStorageFileStream = userStoreForApplication.CreateFile("mylocalfilename"); 

      using (isolatedStorageFileStream) 
      { 
       CopyStream(e.Result, isolatedStorageFileStream); 
      } 
     } 
    } 
+0

感謝ü非常感謝!它工作得很好! – masiboo

相關問題