【问题标题】:upload to a specific folder skydrive上传到特定文件夹 skydrive
【发布时间】:2013-09-24 13:35:54
【问题描述】:

我想上传一个 .txt 列表,并将它们保存在 skydrive 上的自定义文件夹中

like 某人的帐户 -> Skydrive -> 自定义文件夹('testfile')

我试过了

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

但它根本不起作用,它给我一个错误:

URL 包含路径“testfile”,不受支持。

如果我需要获取文件夹ID来上传文件,我如何获取ID?

这是我的代码:

    private async void button_Click(object sender, EventArgs e)
    {
        IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication();
        var temptempout = new List<String>(isoStore.GetFileNames("*").ToList());
        int total = temptempout.Count;
        int now = 0;
        if (temptempout.Count > 0)
        {
            ShowTextDebug.Text = "Uploaded 0 of " + total + " files";
            foreach (String t in temptempout)
            {
                using (var fileStream = isoStore.OpenFile(t, FileMode.Open, FileAccess.Read))
                {
                    try
                    {
                        LiveOperationResult res = await client.BackgroundUploadAsync("me/skydrive/testfile",
                                                                                    new Uri("/shared/transfers/" + t, UriKind.Relative),
                                                                                    OverwriteOption.Overwrite
                                                                                    );
                    }
                    catch (Exception err)
                    {
                        String rrtt = "there is an error while uploading txt " + err.Message;
                        MessageBox.Show(rrtt, "error", MessageBoxButton.OK);
                    }
                }
                now++;
                ShowTextDebug.Text = "Uploaded " + now + " of " + total + " files";
            }
            ShowTextDebug.Text += "\nupload complete";
        }
        else
        {
            MessageBox.Show("no txt exist", "error", MessageBoxButton.OK);
        }
    }

谢谢你帮助我

【问题讨论】:

    标签: c# windows-phone-8 onedrive


    【解决方案1】:

    您需要先获取文件夹 ID。你可以这样做:

    private async Task<string> GetSkyDriveFolderID(string folderName)
    {
        client = App.LiveClient;
    
        LiveOperationResult operationResult = await client.GetAsync("me/skydrive/files?filter=folders");
        var iEnum = operationResult.Result.Values.GetEnumerator();
        iEnum.MoveNext();
        var folders = iEnum.Current as IEnumerable;
    
        foreach (dynamic v in folders)
        {
            if (v.name == folderName)
            {
                return v.id as string;
            }
        }
        return null;
    }
    

    上传文件前调用该方法获取文件夹id:

    string folderId = await GetSkyDriveFolderId("folderName");
    LiveOperationResult res = await client.BackgroundUploadAsync(folderId, new Uri("/shared/transfers/" + t, UriKind.Relative), OverwriteOption.Overwrite);
    

    【讨论】:

      猜你喜欢
      • 2012-08-20
      • 2013-01-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多