2013-07-22 4 views
0

녹음 된 파일을 skydrive에 업로드하려고하는데 다음 코드를 사용하고 있습니다.오류 WP8에서 BackgroundUploadAsync로 파일을 업로드 할 때?

녹음 용;

void StopRecording() 
{ 
    // Get the last partial buffer 
    int sampleSize = microphone.GetSampleSizeInBytes(microphone.BufferDuration); 
    byte[] extraBuffer = new byte[sampleSize]; 
    int extraBytes = microphone.GetData(extraBuffer); 

    // Stop recording 
    microphone.Stop(); 

    // Create MemoInfo object and add at top of collection 
    int totalSize = memoBufferCollection.Count * sampleSize + extraBytes; 
    TimeSpan duration = microphone.GetSampleDuration(totalSize); 
    MemoInfo memoInfo = new MemoInfo(DateTime.UtcNow, totalSize, duration); 
    memoFiles.Insert(0, memoInfo); 

    // Save data in isolated storage 
    using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication()) 
    { 
     using (IsolatedStorageFileStream stream = storage.CreateFile("/shared/transfers/" + memoInfo.FileName)) 
     { 
      // Write buffers from collection 
      foreach (byte[] buffer in memoBufferCollection) 
       stream.Write(buffer, 0, buffer.Length); 

      // Write partial buffer 
      stream.Write(extraBuffer, 0, extraBytes); 
     } 
    } 
} 

파일 업로드 용.

async void OnSaveButtonClick(object sender, RoutedEventArgs args) 
{ 
    Button btn = sender as Button; 
    MemoInfo clickedMemoInfo = btn.Tag as MemoInfo; 
    memosListBox.SelectedItem = clickedMemoInfo; 
    if (this.client == null) 
    { 
     gridSingin.Visibility = Visibility.Visible; 
     memosListBox.Visibility = Visibility.Collapsed; 
    } 
    else 
    { 
     using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication()) 
     { 
      using (var fileStream = store.OpenFile(clickedMemoInfo.FileName, FileMode.Open, FileAccess.Read, FileShare.Read)) 
      { 
       LiveOperationResult res = await client.BackgroundUploadAsync("me/skydrive", 
                      new Uri("/shared/transfers/" + clickedMemoInfo.FileName, UriKind.Relative), 
                      OverwriteOption.Overwrite 
                      ); 
       InfoText.Text = "File " + clickedMemoInfo.FileName + " uploaded"; 
      } 
     } 
    } 
} 

하지만 여기에서 나는이 오류를 얻고있다

LiveOperationResult res = await client.BackgroundUploadAsync("me/skydrive", new Uri("/shared/transfers/" + clickedMemoInfo.FileName, UriKind.Relative), OverwriteOption.Overwrite); 

을 오류를 뻥하고;

형식 'System.Reflection.TargetInvocationException'형식의 처리되지 않은 예외가, 당신이 나를 도울 수

System.Windows.ni.dll

에서하시기 바랍니다 발생?

답변

0

업로드 할 때 파일을 열어 둘 수 없습니다. 이렇게 해보십시오.

using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication()) 
{ 
    if (store.FileExists(fileName)) 
    { 
     client.BackgroundUploadAsync("me/skydrive", new Uri(fileName, UriKind.Relative), 
             OverwriteOption.Overwrite); 

    } 
} 
+0

@Shawn Kendrot –