Metro, skydrive, Windows 8, WinRT

skydrive upload c# metro

Peter Daukintis

A preview of the latest Live SDK for Metro apps can be downloaded here This is for usage with the Windows 8 Consumer Preview (Note that the SDK is a preview version with no go-live license).

After installing you can add a reference via ‘add Reference’ > and select Windows > Extensions in the Reference Manager dialog.


In order to configure sign in on Windows Phone a client ID was required; this is different for Metro-style Apps as you now need to register your app package name and publisher identity here

Once registered you will be provided with a new Package Name – copy this back into your app manifest.

Once this is complete, using the following code you will be able to sign in:


add this namespace declaration


and a sign in button

<live:SignInButton x:Name="btnSignin" Scopes="wl.signin wl.basic wl.skydrive wl.skydrive_update"
                   SessionChanged="SignInButtonSessionChanged" />



The Live id session status is reported by the SessionChanged event so I handle it like this, storing the session object for later use:

private void SignInButtonSessionChanged(object sender, LiveConnectSessionChangedEventArgs e)
    if (e.Status == LiveConnectSessionStatus.Connected)
        _liveConnectSession = e.Session;

Next we need a way to get hold of an image so I just used the File Picker to retrieve one (I added a way to capture an image using the camera but I couldn’t test it so it probably won’t work Sad smile)

Here’s the code for the file picker:

async private void ChooseFile(object sender, RoutedEventArgs e)
    FileOpenPicker openPicker = new FileOpenPicker();
    openPicker.ViewMode = PickerViewMode.Thumbnail;
    openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
    StorageFile file = await openPicker.PickSingleFileAsync();

    if (file != null)
        _filename = file.Name;
        BitmapImage bitmapImage = new BitmapImage();
        _stream = (FileRandomAccessStream)await file.OpenAsync(FileAccessMode.Read);
        myImage.Source = bitmapImage;

and finally, what it was all about, uploading to skydrive:

private void Upload(Stream data, string filename)
    var liveConnectClient = new LiveConnectClient(_liveConnectSession);

    liveConnectClient.UploadCompleted += LiveConnectClientUploadCompleted;
    VisualStateManager.GoToState(this, "Busy", true);
    liveConnectClient.UploadAsync("me/skydrive", filename, true, data, data);

Here’s the ui whilst uploading an image:



and when completed – displaying the json result returned by the upload.




and finally, the image on skydrive.



The project can be found here!441&parid=4F1B7368284539E5!123

Tagged , , , ,

1 thought on “skydrive upload c# metro

  1. Thank you for the steps in simple language. I am not sure which one to use Azure Blob storage or Skydrive. Skydrive is free but I never used on my applications. Do you have any comments.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.