现在的位置: 首页 > 综合 > 正文

WP独立存储相关代码

2012年02月08日 ⁄ 综合 ⁄ 共 1247字 ⁄ 字号 评论关闭
View Code

 1  //获取WP7系统背景主题色调。。
2 public static Theme GetTheme()
3 {
4 if (((Visibility)Application.Current.Resources["PhoneLightThemeVisibility"]) != Visibility.Visible)
5 {
6 return Theme.Dark;
7 }
8 return Theme.Light;
9 }
10
11 //从独立存储指定目录中获取指定文件的字节数。。
12 public static byte[] LoadFromLocalStorage(string szFolder, string szFileName)
13 {
14 IsolatedStorageFile userStoreForApplication = IsolatedStorageFile.GetUserStoreForApplication();
15 if (!userStoreForApplication.DirectoryExists(szFolder))
16 {
17 userStoreForApplication.CreateDirectory(szFolder);
18 }
19 string path = System.IO.Path.Combine(szFolder, szFileName);
20 using (IsolatedStorageFileStream stream = userStoreForApplication.OpenFile(path, FileMode.Open, FileAccess.Read))
21 {
22 return GetAllDataFrom(stream);
23 }
24 }
25 //往独立存储指定目录以指定文件写入字节数组。。
26 public static void SaveToLocalStorage(byte[] rgbData, string szFolder, string szfileName)
27 {
28 if (rgbData != null)
29 {
30 IsolatedStorageFile userStoreForApplication = IsolatedStorageFile.GetUserStoreForApplication();
31 if (!userStoreForApplication.DirectoryExists(szFolder))
32 {
33 userStoreForApplication.CreateDirectory(szFolder);
34 }
35 string path = System.IO.Path.Combine(szFolder, szfileName);
36 using (IsolatedStorageFileStream stream = userStoreForApplication.CreateFile(path))
37 {
38 stream.Write(rgbData, 0, rgbData.Length);
39 }
40 }
41 }

抱歉!评论已关闭.