0

我想将录制的文件上传到 skydrive,我正在使用这些代码

用于录音;

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.Windows.ni.dll 中出现“System.Reflection.TargetInvocationException”类型的未处理异常

请问你能帮帮我吗?

4

1 回答 1

0

尝试上传时无法打开文件。尝试这样做。

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

    }
}
于 2013-07-22T22:54:25.247 回答