Friday, May 16, 2014

Check Whether a Particular Folder Exists in Your OneDrive Using Live SDK

This is a quick post on how you can check whether a particular folder exists in your OneDrive using Live SDK. My requirement here was, for one of my Windows Phone 8 applications, I needed to check whether a particular folder exists in my OneDrive. Following is a very simple method for that.
private static async Task<string> CheckIfFolderExistsAsync(LiveConnectClient client, string folderName)
{
    LiveOperationResult operationResult = await client.GetAsync("me/skydrive/files?filter=folders,albums");
    dynamic result = operationResult.Result;
 
    foreach (var item in result.data)
    {
        if (item.name == folderName)
        {
            return item.id;
        }
    }
    return string.Empty;
}

If a folder exists under given name, it will return the id of the folder and if not, an empty string will be returned.

Happy Coding.

Regards,
Jaliya

No comments:

Post a Comment