【问题标题】:Error When uploading file with BackgroundUploadAsync in WP8?在 WP8 中使用 BackgroundUploadAsync 上传文件时出错?
【发布时间】:2013-07-21 17:42:42
【问题描述】:

我想将我录制的文件上传到 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”类型的未处理异常

你能帮帮我吗?

【问题讨论】:

    标签: c# upload windows-phone-8 onedrive live-connect-sdk


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-09
      • 2018-04-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多