惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

D
Docker
阮一峰的网络日志
阮一峰的网络日志
T
Tailwind CSS Blog
博客园 - 【当耐特】
量子位
博客园 - 叶小钗
有赞技术团队
有赞技术团队
Jina AI
Jina AI
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - Franky
博客园 - 司徒正美
爱范儿
爱范儿
美团技术团队
小众软件
小众软件
酷 壳 – CoolShell
酷 壳 – CoolShell
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
V
V2EX
罗磊的独立博客
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Last Week in AI
Last Week in AI
Hugging Face - Blog
Hugging Face - Blog
I
InfoQ
D
DataBreaches.Net
宝玉的分享
宝玉的分享

博客园 - 十二号的国王

【iOS开发】在ARC项目中使用非ARC文件 实现ZUNE上软件商城的软件星级推荐效果 [Windows Phone 7]开发分享图片的插件(2) [Windows Phone 7]如何判断手机是否有网络连接 [Windows Phone 7]开发分享图片的插件(1) [Windows Phone 7]如何导航页面和页面间传值 [Windows Phone 7]UI对屏幕的自适应的处理 [Windwos Phone 7] Accelerometer [Windwos Phone 7] 获取设备相关信息 [Windows Phone 7] 常用资源(转) XNA:保存数据到文件和从文件读取数据 XNA项目运行错误:No suitable graphics card found. POOM(Pocket Outlook Object Model)开发介绍及应用(转) 剪贴板剪切/复制与粘贴文件+1个待解决的问题 c#枚举-Enum C#读写INI配置文件(转) C#3.0新增特性 - 十二号的国王 - 博客园 关于DBNull vs 快捷键
[Windows Phone 7] Storage
十二号的国王 · 2010-10-13 · via 博客园 - 十二号的国王

现在Windwos Phone 7的数据存储得写入到独立存储空间中,有两种存储方式:1.独立文件存储;2.独立设置存储。

(1)独立文件存储

独立文件存储的使用方法与文件类似

写入:

//Obtain the virtual store for application
IsolatedStorageFile myStore = IsolatedStorageFile.GetUserStoreForApplication();
//Create a new folder and call it "ImageFolder"
myStore.CreateDirectory("ImageFolder");
//Create a new file and assign a StreamWriter to the store and this new file (myFile.txt)
//Also take the text contents from the txtWrite control and write it to myFile.txt
StreamWriter writeFile = new StreamWriter(new IsolatedStorageFileStream("ImageFolder\\myFile.txt", FileMode.OpenOrCreate, myStore));
writeFile.WriteLine(txtWrite.Text);
writeFile.Close();

读取:


     //Obtain a virtual store for application
    IsolatedStorageFile myStore = IsolatedStorageFile.GetUserStoreForApplication();
    //This code will open and read the contents of myFile.txt
    //Add exception in case the user attempts to click “Read button first.
    StreamReader readFile = null;
    try
    {
        readFile = new StreamReader(new IsolatedStorageFileStream("ImageFolder\\myFile.txt", FileMode.Open, myStore));
        string fileText = readFile.ReadLine();
        //The control txtRead will display the text entered in the file
        txtRead.Text = fileText;
        readFile.Close();
    }
    catch
    {
        txtRead.Text = "Need to create directory and the file first.";
    }

(2)独立设置存储

//获取独立设置存储对象
IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;

//写数据
setting["name"]="Bill";
setting["age"]=""20;
setting.save();
//读数据
string Name=setting["name"];

更具体的例子可以看微软SettingsSample的例子,里面有很详细的说明怎么进行独立设置存储。