WP8 - SkyDrive API上传文件错误

时间:2013-12-24 06:53:56

标签: windows-phone-8 onedrive

基本上我遇到了这个问题。所以我已经从我的应用程序在skydrive中创建了一个文件夹,我想将文本文件上传到该文件夹​​,但它只是不让我。 Bascailly我上传文本文件的唯一方法是,如果我将位置设置为“me / skydrive”。我不这样做,以便将文本文件上传到SkyDrive上名为“Pencil Notes”的文件夹。

我的代码太远了:

 Dim myIsolatedStorage As IsolatedStorageFile = IsolatedStorageFile.GetUserStoreForApplication()
    Dim mp1 = TryCast(App.RootFrame.Content, MainMenu)
    Dim dataSource As New List(Of SampleData1)()
    Dim data = TryCast(ItemsListSkyDrive.SelectedItem, SampleData1)

    Dim writeFile As New StreamWriter(New IsolatedStorageFileStream("/shared/transfers/" & data.Name & ".txt", FileMode.Create, myIsolatedStorage))
    Dim Title As String = data.Name
    Dim Message As String = data.Description
    writeFile.WriteLine(Title)
    writeFile.WriteLine(Message)
    writeFile.Close()

    Dim store1 As IsolatedStorageFile = IsolatedStorageFile.GetUserStoreForApplication()
    Using store As IsolatedStorageFile = IsolatedStorageFile.GetUserStoreForApplication()
        Try
            Dim res As LiveOperationResult = Await client.BackgroundUploadAsync("me/skydrive/Pencil Notes", New Uri("/shared/transfers/" & data.Name & ".txt", UriKind.Relative), OverwriteOption.Overwrite)
            MessageBox.Show("Done", "", MessageBoxButton.OK)
            store1.DeleteFile("/shared/transfers/" & data.Name & ".txt")
        Catch ex As Exception
            MessageBox.Show(ex.Message, "", MessageBoxButton.OK)
        End Try
    End Using

1 个答案:

答案 0 :(得分:0)

此PostCompleted事件用于在skydrive上传文件:

client.PostCompleted +=
                        new EventHandler<LiveOperationCompletedEventArgs>(CreateMyFolder_Completed);
 void CreateMyFolder_Completed(object sender, LiveOperationCompletedEventArgs e)
        {
            if (e.Error == null)
            {
               string folderID = (e.Result["id"]).ToString();
                foreach (string item in names)
                {
                    using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication())
                    {
                        string filename = item;
                        if (store.FileExists(filename))
                        {
                            IsolatedStorageFileStream storeStream = store.OpenFile(filename, FileMode.Open, FileAccess.Read);
                            client.UploadAsync(folderID, filename, storeStream, OverwriteOption.Overwrite);

                        }                         
                    }
                }
            }

这会对你有所帮助