wp8 独立存储 总结2(文件存储)
来源:互联网 发布:聊天软件有哪些 编辑:程序博客网 时间:2024/06/05 02:21
一、wp7.1APIs
Isolated Storage Classes
•独立存储类在System.IO.IsolatedStorage命名空间中•IsolatedStorageFile
•表示包含文件和目录的独立存储区
•IsolatedFileStream
•公开独立存储中的文件
Saving Data
private void saveGameToIsolatedStorage(string message){using(IsolatedStorageFile isf =IsolatedStorageFile.GetUserStoreForApplication()){using(IsolatedStorageFileStreamrawStream= isf.CreateFile("MyFile.store")){StreamWriterwriter = newStreamWriter(rawStream);writer.WriteLine(message); // save the messagewriter.Close();}}}Loading Data
private string loadString(){stringresult = null;using(IsolatedStorageFileisf= IsolatedStorageFile.GetUserStoreForApplication()){if(isf.FileExists("Myfile.store"){using(IsolatedStorageFileStreamrawStream= isf.OpenFile(filename, System.IO.FileMode.Open)) {StreamReaderreader = newStreamReader(rawStream);result = reader.ReadLine();reader.Close();}}}return result;}
</pre><pre name="code" class="csharp">下面是ADDpange的部分代码
namespace PhoneApp1{ public partial class AddPage : PhoneApplicationPage { public AddPage() { InitializeComponent(); } protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); if (this.State.ContainsKey("IncompleteEntry")) { this.logtext.Text = this.State["IncompleteEntry"] as string; } } protected override void OnNavigatedFrom(NavigationEventArgs e) { if (e.NavigationMode != System.Windows.Navigation.NavigationMode.Back && e.NavigationMode != System.Windows.Navigation.NavigationMode.Forward) { this.State["IncompleteEntry"] = this.logtext.Text; } base.OnNavigatedFrom(e); } private void ApplicationBarIconButton_Click(object sender, EventArgs e) { SaveEntry(); if (NavigationService.CanGoBack) { NavigationService.GoBack(); } } private void cancel_Click(object sender, EventArgs e) { if (NavigationService.CanGoBack) { NavigationService.GoBack(); } } private async void SaveEntry() { string timeshow = System.DateTime.Now + System.Environment.NewLine; App thisapp = App.Current as App;//利用APP属性传递值 thisapp.logdata = FileStorageOperation.LoadFromIsolatedStorage(); thisapp.logdata = thisapp.logdata + timeshow + logtext.Text + System.Environment.NewLine; FileStorageOperation.SavetoIsolatedStorage(thisapp.logdata); } }}
在APP.XAML.CS加入属性的值
public string logdata
{
set;
get;
}
在显示的页面加入
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
App thisapp = App.Current as App;
thisapp.logdata = FileStorageOperation.LoadFromIsolatedStorage();
showblock.Text = thisapp.logdata;
}
0 0
- wp8 独立存储 总结2(文件存储)
- wp8独立存储 总结
- wp8 独立存储 总结3(应用设置)
- WP8_读写XML WP8数据存储--独立存储文件
- WP8的文件和存储
- 05,WP8的文件和存储
- 05,WP8的文件和存储
- IsolatedStorageFileStream类独立存储文件
- 独立存储
- 独立存储
- WP7开发解惑(2):如何从安装文件夹拷贝文件到独立存储
- Silverlight独立存储之读写文件
- Android文件存储总结
- 数据存储(2)---文件存储
- 详解Silverlight 2中的独立存储
- 详解Silverlight 2中的独立存储(转载)
- 详解Silverlight 2中的独立存储
- Silverlight之独立存储(10)
- VC U盘病毒模版
- 下载Android开发工具网址
- 亚马逊危险了!面临新公司和科技巨头的颠覆
- POJ 1654 Area(多边形面积)
- ios error:has been modified since the precompiled header,UIKit-54I6A640FSCK.pcm' was built
- wp8 独立存储 总结2(文件存储)
- 硅谷女工程师业余热衷练举重
- nyoj 44 子串和(最大连续子序列和)
- C/C++中手动获取调用堆栈
- 递归求Fibonacci数列
- UVA 11181 Probability|Given
- leetcode: Permutation Sequence
- android4.4 锁屏(Keyguard)源码分析总结
- 【记录】将combobox设成只读的简单方法