Over a million developers have joined DZone.

Using SkyDrive in your Windows Phone applications: Part 2

DZone 's Guide to

Using SkyDrive in your Windows Phone applications: Part 2

· Mobile Zone ·
Free Resource

This is part two on how to use Skydrive in your Windows Phone applications.  Part one was an introduction to how to sign in into Skydrive.

In this part, let’s try to read the Skydrive’s folders.

I will use the ApplicationBarIconButton to read from my Skydrive then put the result in a very simple list in another page.

So first, let’s create a new Windows Phone page , I’ll call it “ content.xaml”.

I’ll change the Application title to “ Skydrive” and the page title to “ Folders”. I will also add a listbox.

      <!--TitlePanel contains the name of the application and page title-->
         <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
            <TextBlock x:Name="ApplicationTitle" Text="Skydrive" Style="{StaticResource PhoneTextNormalStyle}"/>
             <TextBlock x:Name="PageTitle" Text="Folders" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>

         <!--ContentPanel - place additional content here-->
        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
             <ListBox Name="list">
                       <StackPanel Orientation="Horizontal">
                            <TextBlock Name="folder" Text="{Binding Name}"/>


Now we need to fill that listBox.

In the MainPage.xaml, let’s add an ApplicationBarIconButton ( it is already there as a commented code):

       <shell:ApplicationBar IsVisible="True" IsMenuEnabled="True">
            <shell:ApplicationBarIconButton IconUri="/Images/appbar_button1.png" Text="Read " Click="ApplicationBarIconButton_Click" />

When you click on the button , you should be able to get your content from Skydrive if you are signed in and see it on that listbox we put in “content.xaml”

private void ApplicationBarIconButton_Click(object sender, EventArgs e)
   if (session == null)
       infoTextBlock.Text = "You must sign in first.";
       LiveConnectClient client = new LiveConnectClient(session);
        client.GetCompleted +=
            new EventHandler<LiveOperationCompletedEventArgs>(getFolderProperties_Completed);


void getFolderProperties_Completed(object sender, LiveOperationCompletedEventArgs e)
    if (e.Error == null)
        List<object> data = (List<object>)e.Result["data"];
        foreach (IDictionary<string, object> content in data)
            SkyDriveContent skyContent = new SkyDriveContent();
            skyContent.Name = (string)content["name"];
        this.NavigationService.Navigate(new Uri("/content.xaml", UriKind.Relative));
        infoTextBlock.Text = "Error calling API: " + e.Error.Message;


The result is stored in a “ SkydriveContent “ list :

public static List<SkyDriveContent> ContentList = new List<SkyDriveContent>();
public class SkyDriveContent
    {   public string Name { get; set; }
        public string Description { get; set; }

In the Content.xaml.cs , we will tell the listbox to get its items from the ContentList:

public content()
      list.ItemsSource = MainPage.ContentList;

That is all you need to be able to read your Skydrive folders in your Windows Phone application.

There is also an interesting and helpful post in Silverlight Show by Samidip Basu about the usage of Skydrive with Windows Phone.

Source: http://rabeb.wordpress.com/2012/02/02/using-skydrive-in-your-windows-phone-applications-part2/


Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}