Click here to Skip to main content
12,826,440 members (22,658 online)
Click here to Skip to main content
Add your own
alternative version


2 bookmarked
Posted 8 May 2013

Windows 8 App - Data storage in files using Windows.Storage namespace

, 10 May 2013 CPOL
Rate this:
Please Sign up or sign in to vote.
Learn to store/read data from Windows 8 app and available file storage options for Win8 apps.


Win 8 App can store data into 3 folders using these classes under Windows.Storage namespace. 

  • Windows.Storage.ApplicationData.current.localFolder
  • Windows.Storage.ApplicationData.current.roamingFolder
  • Windows.Storage.ApplicationData.current.temporaryFolder

Local Folder 

It stores files under LocalState folder under App Package. These files are not synchronized on all machines the user signed in with same account like Window Phone, Tablet or PC and it remain on the machine on which the file was originally created.

Roaming Folder  

It stores files under RoamingState folder under App Package. These files are synchronized on all machines the user signed in with same account like Window Phone, Tablet or PC. But the synchronization will not be instant. It will depend on internet access on these devices or other factors like the device not ready to send/receive data. Roaming data should be less than the available quota (check RoamingStorageQuota property), or else the App will not able the synchronize data under RoamingState folder. Files will be synchronized when the application closed/saved the file after editing.

Temporary Folder   

It stores files under TempState folder under App Package. The files under this folder can be deleted when these are not in use or depends on available disk capacity and the age of a file. Do not use this folder to store important information from user.   

All these are be located under the App package folder.

This code example will create a sampleFile.txt under the RoamingState folder.


Source Code



<Page x:class="TestApp.MainPage" 

  <Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
        <TextBlock x:Name="TextBlock1" HorizontalAlignment="Left" 
           Height="40" Margin="41,127,0,0" TextWrapping="Wrap" 
           Text="TextBlock" VerticalAlignment="Top" Width="201" 
        <Button Content="Read" HorizontalAlignment="Left" 
           Height="40" Margin="394,54,0,0" VerticalAlignment="Top" 
           Width="134" Click="Read_Button_Click"/>
        <TextBox x:Name="TextBox1" HorizontalAlignment="Left" 
           Height="33" Margin="41,61,0,0" TextWrapping="Wrap" 
           Text="TextBox" VerticalAlignment="Top" Width="168"/>
        <Button Content="Write" HorizontalAlignment="Left" 
           Height="40" Margin="240,54,0,0" 
           VerticalAlignment="Top" Width="134" 

MainPage.xaml.cs ( with Roaming Storage)

using System;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.Storage;

namespace TestApp
    public sealed partial class MainPage : Page
        StorageFolder StorageFolder = null;
        const string filename = "sampleFile.txt";

        public MainPage()
            StorageFolder = ApplicationData.Current.RoamingFolder;

        private void Read_Button_Click(object sender, RoutedEventArgs e)

        private void Write_Button_Click(object sender, RoutedEventArgs e)

        async void ReadText()
            StorageFile file = await StorageFolder.GetFileAsync(filename);
            TextBlock1.Text  = await FileIO.ReadTextAsync(file);
        async void WriteText()
            StorageFile file = await StorageFolder.CreateFileAsync(filename, 
            await FileIO.WriteTextAsync(file, TextBox1.Text);

For local and temporary storage choose different folder options from ApplicationData.Current.


Local Storage

public MainPage()
    StorageFolder = ApplicationData.Current.LocalFolder;

Temporary Storage 

public MainPage()
    StorageFolder = ApplicationData.Current.TemporaryFolder;


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Surender Singh (CodeToastDev)
Software Developer
United States United States
Personal Blog :

You may also be interested in...

Comments and Discussions

QuestionAbout Windows 8 App - Data storage in files using Windows.Storage namespace Pin
Member 1209249521-May-16 5:50
memberMember 1209249521-May-16 5:50 
QuestionNot an article... Pin
Dave Kreskowiak10-May-13 11:45
mvpDave Kreskowiak10-May-13 11:45 
Task out the screen shots and the code snippets and there's nothing left.

Articles are like research papers. They discuss the topic at hand in depth.

AnswerRe: Not an article... Pin
Surender Singh (CodeToast)11-May-13 3:26
professionalSurender Singh (CodeToast)11-May-13 3:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170326.1 | Last Updated 10 May 2013
Article Copyright 2013 by Surender Singh (CodeToastDev)
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid