Monday, September 26, 2011

Live SkyDrive API: Get List of Folder's Files

The new Live Connect SkyDrive API, which was released in prelimary form at Build 2011, finally delivers an "official" way to manipulate files and folders on SkyDrive. For being a preview release, the docs look reasonably complete.

However, one thing that wasn't clear to me (from the docs) was how to iterate through the contents of a folder while, for example, searching for a particular file.

So...here's a bare-bones code snippet that shows how to search the root folder of the signed-in user's SkyDrive for the file "test.txt".


private void FindFileTestDotTxt()
{
    client.GetCompleted += 
        new EventHandler<LiveOperationCompletedEventArgs>(client_GetCompleted);
    client.GetAsync("me/skydrive/files");
}

void client_GetCompleted(object sender, LiveOperationCompletedEventArgs e)
{
    Dictionary<string, object> resultDict = 
        (Dictionary<string, object>) e.Result;

    List<object> items = (List<object>)resultDict["data"];

    foreach (object o in items)
    {
        Dictionary<string, object> item = (Dictionary<string, object>)o;

        if (item["name"].ToString() == "test.txt")
        {
            // found it 
            Console.WriteLine("File URL: {0}", item["source"].ToString());
            break;
        }
    }
}

Wednesday, June 1, 2011

Windows Phone 7 Emulator Saved-State Corrupted

This morning, quite out of the blue, the Windows Phone 7 emulator (Mango release) refused to initialize. The error message complained about a corrupted saved-state file and recommended that I delete a particular file named SOME_LONG_GUID.DES in C:\ProgramData\Microsoft\XDE.

After some poking around, I found the file (which actually ends in DESS, not DES), deleted it and restarted the emulator. No dice. Now I'm getting some sort of "internal error" message.

Next I deleted the SS file also found in C:\ProgramData\Microsoft\XDE. Still broken.

Restored the DESS file, but not the SS file. (SS == Shared State?). Now we have some progress, but the emulator is clearly booting from scratch and takes several minutes to initialize. Deploying apps from VS doesn't appear to work either.

As a hail mary, I restored the SS file and tried again. All's well!

Hope this helps someone else with the same issue.