Skip to content

Latest commit

 

History

History
88 lines (65 loc) · 4.84 KB

storage-use-store-apps.md

File metadata and controls

88 lines (65 loc) · 4.84 KB
title description services documentationcenter author manager editor ms.assetid ms.service ms.workload ms.tgt_pltfrm ms.devlang ms.topic ms.date ms.author
Use Azure storage in Windows Store apps | Microsoft Docs
Learn how to create a Windows Store app that uses Azure Blob, Queue, Table, or File storage.
storage
mmacy
timlt
tysonn
63c4b29d-b2f2-4d7c-b164-a0d38f4d14f6
storage
storage
mobile-windows-store
dotnet
article
12/08/2016
marsma

How to use Azure Storage in Windows Store apps

Overview

This guide shows how to get started with developing a Windows Store app that makes use of Azure Storage.

Download required tools

Develop apps

Getting ready

Create a new Windows Store app project in Visual Studio 2012 or later:

store-apps-storage-vs-project

Next, add a reference to the Azure Storage Client Library by right-clicking References, clicking Add Reference, and then browsing to the Storage Client Library for Windows Runtime that you downloaded:

store-apps-storage-choose-library

Using the library with the Blob and Queue services

At this point, your app is ready to call the Azure Blob and Queue services. Add the following using statements so that Azure Storage types can be referenced directly:

using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Auth;

Next, add a button to your page. Add the following code to its Click event and modify your event handler method by using the async keyword:

var credentials = new StorageCredentials(accountName, accountKey);
var account = new CloudStorageAccount(credentials, true);
var blobClient = account.CreateCloudBlobClient();
var container = blobClient.GetContainerReference("container1");
await container.CreateIfNotExistsAsync();

This code assumes that you have two string variables, accountName and accountKey. They represent the name of your storage account and the account key that is associated with that account.

Build and run the application. Clicking the button will check whether a container named container1 exists in your account and then create it if not.

Using the library with the Table service

Types that are used to communicate with the Azure Table service depend on WCF Data Services for the Windows Store app library. Next, add a reference to the required WCF libraries by using the Package Manager Console:

store-apps-storage-package-manager

Use the following command to point Package Manager to the location on your machine:

Install-Package Microsoft.Data.OData.WindowsStore -Source "C:\Program Files (x86)\Microsoft WCF Data Services\5.0\bin\NuGet"

This command will automatically add all required references to your project. If you do not want to use the Package Manager Console, you can add the WCF Data Services NuGet folder on your local machine to the list of package sources and then add the reference through the UI, as described in Managing NuGet Packages Using the Dialog.

When you have referenced the WCF Data Services NuGet package, change the code in your button's Click event:

var credentials = new StorageCredentials(accountName, accountKey);
var account = new CloudStorageAccount(credentials, true);
var tableClient = account.CreateCloudTableClient();
var table = tableClient.GetTableReference("table1");
await table.CreateIfNotExistsAsync();

This code checks whether a table named table1 exists in your account, and then creates it if not.

You can also add a reference to Microsoft.WindowsAzure.Storage.Table.dll, which is available in the same package that you downloaded. This library contains additional functionality, such as reflection-based serialization and generic queries. Note that this library does not support JavaScript.