简体   繁体   中英

WP7 Isolated Storage Text Document Read Line

Is there a way using Isolated storage ie a Text document, to grab the text on a certain line. I would like to save variables to a text document on my settings page of my app. Then go back to the main page and read the variable saved on line 3. I already know how to save them. just not read certain lines.

Also is the text document created by my app going to still be there if i close and reopen the app?

Try this

using( TextReader reader = new StreamReader( 
         new IsolatedStorageFileStream( "myFile.txt", System.IO.FileMode.Open, 
           IsolatedStorageFile.GetUserStoreForApplication() ) ) {

    string line = reader.ReadLine(); // first line, discard
    line = reader.ReadLine();        // second line, discard
    line = reader.ReadLine();        // third line, read the variable value
}

However, you might be better off using the IsolatedStorageSettings class to store settings (the link contains example usage). Another option is to put all your settings into a serializable class and use an XmlSerializer to save / read the settings. Both these approaches would not require parsing the file manually.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM