Over a million developers have joined DZone.

Windows Azure Storage Client Library for Windows Phone: Part 1

DZone's Guide to

Windows Azure Storage Client Library for Windows Phone: Part 1

· Mobile Zone
Free Resource

Windows Azure Storage Client Library allows you to perform operations on Windows Azure storage from Windows Phone. Using Windows Azure Storage Client, you can

  1. Perform operations on Table
  2. Perform operations on Queue
  3. Perform Operations on BLOB

If you are not using Windows Azure Storage Client Library then to work with Windows Azure Storage you may need to create a WCF Service. Windows Phone will make a call to Service and Service will use Windows Azure Storage library to perform operations on Azure Storage. However using Windows Azure Storage Client for Windows Phone, you can directly perform operations on Windows Azure Storage.

You can get Windows Azure Storage Client Library and install it using NuGet. Read more about NuGet here. Once you have installed NuGet go ahead and create a Windows Phone 7.1 application by choosing target Windows Phone Version 7.1


After successful creation of project go to Tools then Library Package Manager, you will get option for Package Manager Console. Go ahead and select that option.


In bottom of Visual studio you will get Package Manage Console. Go ahead and install Phone.Storage package to the project.

You can install a package with below command

PM> Install-Package Phone.Storage


After successful installation of Phone.Storage package, you should have below references and file in solution explorer.


StorageInitializer.cs is very important class. In this class you can set whether you want to perform operation on local development fabric storage or on the azure storage. If you closely look into this file, you will find there are three sections.

  1. To configure to connect with local development fabric storage or Windows Azure Storage Emulator.
  2. To configure to connect with Windows Azure Web Role that contains Windows Azure Storage Proxies
  3. To configure to connect with Windows Azure Storage directly.

All the settings are commented but to work with storage of Windows Azure Emulator. If you want to work with Windows Azure Storage directly, you can do that by commenting third section of the file and providing Account Name and Account Key. Below is the uncommented section in file StorageInitalizer.cs. You need to provide your Windows Azure Storage account name and key.


Next let us say you want to create a table called Student. For that add a class called Student. Student entity class is inherting TableServiceEntity class.


using Microsoft.WindowsAzure.Samples.Phone.Storage;

namespace PhoneApp9
public class Student :TableServiceEntity
public string Name { get; set; }
public string RollNumber { get; set; }
public string Grade { get; set; }


Next as the design of the page, I have put a button and on click event of the button, Student table will get created if not exist and one row will get added.

Design of the page is as below,


<Grid x:Name="LayoutRoot" Background="Transparent">
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>

<!--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="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock x:Name="PageTitle" Text="page name" 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">
<Button x:Name="btnCreateTable" Height="100" Content="Create Table" Margin="46,254,128,254" Click="btnCreateTable_Click" />


On the click event of the button, first you need to resolve table client as below. Set the table name.


After resolving Table client, you need to create table as below,


Once table is created you need to resolve the context to add rows in the table.


You can very much modify above code by getting value to be inserted from the user. In this case I am hardcoding the vale. On putting all codes together you should have below code behind.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Microsoft.WindowsAzure.Samples.Phone.Storage;

namespace PhoneApp9
public partial class MainPage : PhoneApplicationPage
// Constructor
public MainPage()

private void btnCreateTable_Click(object sender, RoutedEventArgs e)
var tableClient = CloudStorageContext.

var tableName = "Student";

p =>
var context = CloudStorageContext.
var sampleData = new Student
{  Grade = "A",

context.AddObject(tableName, sampleData);

asyncResult =>
var response = context.EndSaveChanges(asyncResult);



Once you run on click event of the button you should able to add row in the table. I hope this post is useful. Thanks for reading.

 Source: http://debugmode.net/2012/01/09/windows-azure-storage-client-library-for-windows-phone-part-1/


Opinions expressed by DZone contributors are their own.


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.


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

{{ parent.tldr }}

{{ parent.urlSource.name }}