0

.txt のリストをアップロードして、skydrive のカスタム フォルダーに保存したい

誰かのアカウントのように -> 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);
        }
    }

私を助けてくれてありがとう

4

1 に答える 1

4

最初にフォルダー 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);
于 2013-09-24T13:57:02.757 に答える