locked
How do we do lacalised storage in windows 8 app

    Question

  • I want to store some data from a textbox in the localised storage of the windows 8 app and retirve it once again when the user clicks the app how do I do that

    In windows phone this is my code

    {
                    IsolatedStorageFile ISF = IsolatedStorageFile.GetUserStoreForApplication();
                    //create new file
                    using (StreamWriter SW = new StreamWriter(new IsolatedStorageFileStream("Infoa.txt", FileMode.Create, FileAccess.Write, ISF)))
                    {
                        string text = adminn.Text;
                        SW.WriteLine(text);
                        SW.Close();
                        MessageBox.Show("Contacts have been saved");
                    }
                    using (StreamWriter SW = new StreamWriter(new IsolatedStorageFileStream("Info.txt", FileMode.Create, FileAccess.Write, ISF)))
                    {
                        string texta = admine.Text;
                        SW.WriteLine(texta);
                        SW.Close();
    
                    }


    pratik

    Thursday, March 27, 2014 5:43 AM

Answers

  • Here are 2 options:

    private async void btnSave_Click(object sender, RoutedEventArgs e)
    {
        string content = txtUserInput.Text;
        StorageFolder localFolder = ApplicationData.Current.LocalFolder;
                
        StorageFile targetFile = await localFolder.CreateFileAsync("MyFile.txt", CreationCollisionOption.ReplaceExisting);
    
        if (targetFile != null)
        {
            /* Option 1 */
            using (StreamWriter SW = new StreamWriter(await targetFile.OpenStreamForWriteAsync()))
            {
                SW.WriteLine(content);
            }
            /**/
    
            /* Option 2 */
            //await FileIO.WriteTextAsync(targetFile, content);
            /**/
        }
    }
    
    private async void btnLoad_Click(object sender, RoutedEventArgs e)
    {
        string content = string.Empty;
        StorageFolder localFolder = ApplicationData.Current.LocalFolder;
    
        StorageFile targetFile = await localFolder.CreateFileAsync("MyFile.txt", CreationCollisionOption.OpenIfExists);
        if (targetFile != null)
        {
            /* Option 1 */
            using (StreamReader SW = new StreamReader(await targetFile.OpenStreamForReadAsync()))
            {
                content = await SW.ReadToEndAsync();
            }
            /**/
    
            /* Option 2 */
            //content = await FileIO.ReadTextAsync(targetFile);
            /**/
        }
    
        txtUserInput.Text = content;
    }

    You can refer following link for details:

    Quickstart: Reading and writing files


    If a post solves the problem you asked, please mark it as Answer.


    Thursday, March 27, 2014 11:17 AM