cookieChoices = {};

Thursday, 24 April 2014

Share Data Between Applications

Main Page.Xaml:

 <Grid x:Name="LayoutRoot" Background="White">

        <Button Content="Set To File" Height="57" HorizontalAlignment="Left" Margin="70,92,0,0" Name="btnSetFile" VerticalAlignment="Top" Width="98" Click="btnSetFile_Click" />
        <Button Content="Get From File" Height="57" HorizontalAlignment="Right" Margin="0,92,90,0" Name="btnGetFile" VerticalAlignment="Top" Width="100" Click="btnGetFile_Click" />

    </Grid>
MainPage.Xaml.cs:

private void btnSetFile_Click(object sender, RoutedEventArgs e)
        {
            IsolatedStorageFile myStorage = IsolatedStorageFile.GetUserStoreForApplication();

            using (StreamWriter sw = new StreamWriter(new IsolatedStorageFileStream("ISData.txt", FileMode.Create, FileAccess.Write, myStorage))) 
            {
                sw.WriteLine("Isolated Storage Demo");
                sw.Close();
            }
        }

        private void btnGetFile_Click(object sender, RoutedEventArgs e)
        {
            IsolatedStorageFile myStorage = IsolatedStorageFile.GetUserStoreForApplication();

            IsolatedStorageFileStream fs = myStorage.OpenFile("ISData.txt", FileMode.Open, FileAccess.Read);

            using (StreamReader sr = new StreamReader(fs))
            {
               MessageBox.Show(sr.ReadLine());
            }


        }

No comments:

Post a Comment