【问题标题】:WP8 - SkyDrive API Uploading files errorWP8 - SkyDrive API 上传文件错误
【发布时间】:2013-12-24 06:53:55
【问题描述】:

基本上我遇到了这个问题。因此,我从我的应用程序中在 skydrive 中创建了一个文件夹,我想将一个文本文件上传到该文件夹​​,但它根本不允许我这样做。基本上,我可以上传文本文件的唯一方法是将位置设置为“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

【问题讨论】:

  • 我发布了一个答案,它会对你有所帮助....实际上我在 c# 中提供了代码,但你可以在你的代码中使用

标签: windows-phone-8 onedrive


【解决方案1】:

此 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);

                        }                         
                    }
                }
            }

这对你有帮助

【讨论】:

  • 谢谢你,但我没有工作 :( 没有 LiveOperationCompleted 事件。还有其他方式吗?
  • 我正在使用最新版本的 Live SDK。我需要做的就是确保将文件上传到创建的文件夹。没有其他的。虽然它可以上传到 SkyDrive 文件夹而不是任何子文件夹,但这很奇怪。
  • 您在哪里询问有关将文件上传到查询中的子文件夹的问题?
  • 好吧,我以为你明白了?如果不后悔的话。
  • 如果我没记错的话,你要的是文件夹,请确保在发布任何查询之前
猜你喜欢
  • 2013-01-07
  • 1970-01-01
  • 2012-08-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多