Question

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

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

i have tried

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:

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

if i need to get folder ID to upload the file, how do i get the ID?

here is my code:

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

thanks for helping me

Was it helpful?

Solution

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;
}

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);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top