上传到特定的文件夹skydrive [英] upload to a specific folder skydrive

查看:95
本文介绍了上传到特定的文件夹skydrive的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要上传.txt列表,并将其保存在skydrive上的自定义文件夹中

i want to upload a list of .txt, and keep them in a custom folder on skydrive

就像某人的帐户-> Skydrive->自定义文件夹("testfile")

like Someone's Account -> Skydrive -> custom folder ('testfile')

我尝试过

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

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

but it doesn't work at all, it give me an error of:

URL包含路径"testfile",该路径不受支持.

The URL contains the path 'testfile', which isn't supported.

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

if i need to get folder ID to upload the file, how do i get the 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);
        }
    }

感谢您的帮助

推荐答案

您需要首先获取文件夹ID.您可以按照以下步骤进行操作:

You need to get the folder id first. You can do it as follows:

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:

Call this method before uploading the file to get the folder id:

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

这篇关于上传到特定的文件夹skydrive的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆