开发者

WP7 Isolated Storage Text Document Read Line

开发者 https://www.devze.com 2023-04-09 15:00 出处:网络
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 te开发者_开发知识库xt document on my settings page of my app. Then go

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 te开发者_开发知识库xt 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消