Today we are going to learn how to store and retrieve data from the Roaming application data storage in Windows 8 Apps. In my previous article we learned about the Temporary Application data location in Windows 8 Apps.
Sometimes when the user's apps are installed on multiple devices, the user needs to keep their data in a Roaming location. For that you need to use Roaming data in your app. By using Roaming Application Data Storage the user is able to store their application data across multiple device or locations. The data is then synchronized among multiple devices. Windows enables the user to replicate the data kept in the roaming locations and automatically updates the other devices where the user's application is installed.
The the size of the data stored in a Roaming location is limited for each application. The user cannot Roam with a large amount of data. If the size of the data exceeds the limit specified for storing the data then Windows does not replicate application data to the cloud.
I suggest you do not to store large size files to the Roaming Application Data. Use Roaming Application Data to keep as small amout of information as possible like small links, URL, small data files etc.
The data in Roaming Application data can change any time. You should perform some necessary task whenever application data is changed.
Now, we are trying to save user data to Roaming Application data storage and also retrieve from it. So, now we proceed to create a Windows 8 Store blank application and data to Roaming Application data storage.
Step 1
First create a Blank Application using C# and XAML.
Step 2
First of all we need to register for the data changed event, so that we receive updated data when data gets changed to the roaming devices; see:
public LandingPage()
{
this.InitializeComponent();
Windows.Storage.ApplicationData.Current.DataChanged +=
new TypedEventHandler<ApplicationData, object>(DataChangeHandler);
}
void DataChangeHandler(Windows.Storage.ApplicationData appData, object o)
{
// TODO: Refresh your data
}Step 3
I've created a simple blank XAML page:
<Page
x:Class="savinguserdataonsuspended.MainPage"
IsTabStop="false"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:savinguserdataonsuspended"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<Canvas>
<TextBox Canvas.Left="249.977" TextWrapping="Wrap" Canvas.Top="67.89" x:Name="IdTextBox"
RenderTransformOrigin="0.5,0.5" UseLayoutRounding="False" Width="259.477"
d:LayoutRounding="Auto"/>
<TextBlock Canvas.Left="90" FontSize="30" TextWrapping="Wrap" Text="Email ID"
Canvas.Top="75"/>
<TextBox Canvas.Left="250" TextWrapping="Wrap" Canvas.Top="130" x:Name="NameTextBox"
Width="261"/>
<TextBlock Canvas.Left="85" TextWrapping="Wrap" Text="Name" FontSize="30" Canvas.Top="129"/>
<Button x:Name="save" Content="Login" Click="save_Click_1" FontSize="25" Canvas.Top="210"
Canvas.Left="187" Height="62" Width="154"></Button>

naren dranPosted Feb 6, 2013, 5:17 AM
Access Denied error is coming.....
Ratul NandiPosted Sep 16, 2012, 11:39 PM
very helpful piece of information. should i use this feature to store data for an app which requires the user to save some data daily?