Question

I can save text file into the isolated storage, but how to add in the textblock such as profile saved 1, profile saved 2? to let it continue.

below is my textblock:

textBlock5.Text = "Profile 1 Name and Admin Saved";

I would like the profile 1 to go to profile 2 when the user saves the second record. Then from the third record onwards it will be multiple name and admin saved.

Isolated storage of a windows phone 7.1, while I have stored a text file into it. Profile 1 and 2 is the things i would like to show in the textBlock5.Text when user clicked on the save button. Trying to achieve when user click one time of the button, it shows "Profile 1 Name and Admin Saved", when user click the second time which second data is stored, is "Profile 2 Name and Admin Saved", and when user click the save button on the third or more times, it shows "Multiple Profile Name and Admin Saved".

 //get the storage for your app 
        IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication();
        //define a StreamWriter
        StreamWriter writeFile;

        if (!store.DirectoryExists("SaveFolder"))
        {
            //Create a directory folder
            store.CreateDirectory("SaveFolder");
            //Create a new file and use a StreamWriter to the store a new file in the directory we just created
            writeFile = new StreamWriter(new IsolatedStorageFileStream("SaveFolder\\SavedFile.txt", FileMode.CreateNew, store));
        }
        else
        {
            //Create a new file and use a StreamWriter to the store a new file in the directory we just created
            writeFile = new StreamWriter(new IsolatedStorageFileStream("SaveFolder\\SavedFile.txt", FileMode.Append, store));
        }


        StringWriter str = new StringWriter();
        str.Write(textBox1.Text);
        str.Write(",");
        str.Write(textBox2.Text);


        writeFile.WriteLine(str.ToString());

        writeFile.Close();

        textBlock5.Text = "Profile 1 Name and Admin Saved";
Était-ce utile?

La solution

You should create your own control if you want to save UIControls in IsolatedStorage (at least in windows phone). This question should help you to get through the issue you are having.

So basically you create something like that

[DataContract]
public class MyTextBox : TextBox
{
     // your implementations here
     [DataMember]
     public string Name { get; set;}
}

for all controllers you need. The code above is not tested so it might not work, but I hope you get the idea.

EDIT

For each property you insert in the class, you must use the Attribute Flag [DataMember]. In this manner you can serialize in the IsolatedStorage all informations you need

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top