Tuesday, November 12, 2013

SkyDrive Browse Task for Windows Phone 8

I love the task-based way of handling platform features on Windows Phone.  It works great for choosing or taking photos, sending email/SMS, or taking a user to Marketplace.  One inexplicable omission is that you have no way to let a user select files from SkyDrive, even though Windows Phone is supposed to be connected to the cloud!  To remedy this, I've created a fairly simple task-based SkyDrive browser for selecting files.  I made it look like the SkyDrive browser used by Office Mobile 15.  This displays the files and folders at root, along with sharing information.  You can tap a folder to enter it, the "up" button to go back a folder, or a file to select it.  Selecting a file passes it back to the caller (your app) so you can open it or do whatever you need.  The library currently supports English, Spanish, German, and French.

Preview image of SkyDrive file browser for Windows Phone 8


To use the library:

  1. Use NuGet Package Manager in Visual Studio to reference ArianKulp.SkyDrive.BrowseTask (direct link below).
  2. In your app, integrate Windows Live LiveClient authentication.
  3. Create the SkyDriveBrowseTask object and pass it the LiveClient.  This is required as it assumes that you are already handling authentication login/logoff in your own way.
  4. Handle the Completed event to deal with the selected file path (or canceled operation).
Handle the request:

var t = new SkyDriveBrowserTask();
t.LiveClient = App.LiveClient;
t.Extensions = "xlf;xliff";
t.Completed += SkyDrive_Completed;
t.Show();

Handle the result:
async void SkyDrive_Completed(object senderSkyDriveResult e)
{
    if (e.Error != null)
    {
        // TODO: Handle the error
    }
    else if (e.TaskResult != Microsoft.Phone.Tasks.TaskResult.Cancel)
    {
        var file = e.ChosenItem;
        // TODO: Do something with the returned file
    } }

Link: SkyDrive Browse Task