Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

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

Discover how to focus on operators for Reactive Programming and how they are essential to react to data in your application.  Brought to you in partnership with Wakanda

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}"/>
       </StackPanel>

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

             </ListBox>
        </Grid>


Now we need to fill that listBox.

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

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


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.";
   }
   else
   {
       LiveConnectClient client = new LiveConnectClient(session);
        client.GetCompleted +=
            new EventHandler<LiveOperationCompletedEventArgs>(getFolderProperties_Completed);
        client.GetAsync("/me/skydrive/files");
    }

}

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"];
            ContentList.Add(skyContent);
        }
        this.NavigationService.Navigate(new Uri("/content.xaml", UriKind.Relative));
    }
    else
    {
        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()
{
      InitializeComponent();
      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/

Learn how divergent branches can appear in your repository and how to better understand why they are called “branches".  Brought to you in partnership with Wakanda

Topics:

Published at DZone with permission of Rabeb Othmani, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

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

{{ parent.tldr }}

{{ parent.urlSource.name }}