Search code examples
c#windows-store-appswindows-store

Store and Retrieve in Windows Store Apps


I am very new in Windows Store Apps. I have created the following app:

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <Grid.RowDefinitions>
        <RowDefinition Height="100"></RowDefinition>
        <RowDefinition Height="Auto"></RowDefinition>
    </Grid.RowDefinitions>

    <TextBlock Text="Storage Application" Margin="30" FontFamily="Times New Roman" FontSize="36"></TextBlock>
    <StackPanel Grid.Row="1" Orientation="Vertical">
        <StackPanel Orientation="Horizontal">
            <TextBlock Text="Name" Margin="30" HorizontalAlignment="Left" FontSize="30" Width="91"></TextBlock>
            <TextBox x:Name="TxtName" Width="200"  Margin="30"></TextBox>
        </StackPanel>
        <StackPanel Orientation="Horizontal">
            <TextBlock Text="Course" Margin="30" FontSize="30"></TextBlock>
            <TextBox x:Name="TxtCouse" Width="200"  Margin="30"></TextBox>
        </StackPanel>
        <StackPanel Orientation="Horizontal">
            <TextBlock Text="City" Margin="30" FontSize="30" Width="91"></TextBlock>
            <TextBox x:Name="TxtCity" Width="200"  Margin="30"></TextBox>
        </StackPanel>
        <StackPanel Orientation="Horizontal">
            <Button x:Name="btnSearch" Content="Submit" Height="60" FontSize="20" Click="btnSearch_Click" Width="160" />
            <TextBlock Margin="30" FontSize="30" Width="195" Height="38"></TextBlock>
        </StackPanel>
    </StackPanel>
</Grid>

Now how do I store in the Windows app local storage? There is a solution with the IsolatedStorage but I did not find this class in the app.


Solution

  • In Windows Store App, You can use ApplicationData in Windows.Storage namespace to manage file and settings.

    You can storage key/value settings using LocalSettings/RoamingSettings.

    And you can storage file using LocalFolder/RoamingFolder/TemporaryFolder.

    Here is the MSDN link: ApplicationData class

    And here is the example of LocalFolder: MSDN ApplicationData.LocalFolder | localFolder property