All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
ASP.NET2.0中将文件上传到数据_[Asp.Net教程]
ASP.Net环境下使用Jmail组件发送邮件_[Asp.Net教程]
构建安全的Xml,Web,Service系列(三)_[Asp.Net教程]
五种形式的网页弹出窗口代码详解_JavaScript技术_编程技术
用PHP程序直接调用文本文件内容的实例_php资料_编程技术
Apache配置文件里的LogLevel指令介绍_php资料_编程技术
.NET3.5和VS2008中的ASP.NET,AJAX_.net资料_编程技术
XML规范和学习资源小结_[XML教程]
用ajax、asp编写的查询程序(原创)_[AJAX教程]
畸形发展的互联网:新生个人网站很压抑_JavaScript技术_编程技术
Reading number is top 10 pictures
接财神,大吉大利,财源滚滚来
The money of more than 100 countries and regions18
一千块钱如何创业
The Soviet union swimsuit exposure in the 70 year3
这才叫绝色美女2
这才是真正的人体艺术3
Plump, too plump!2
Athena chu perspective cheongsam shine with New York
Sora aoi on twitter1
刘亦菲写真集1
Download software ranking
Call Of Duty2
Sora aoi, the nurse, uniform ,nursing assistant
asp.netWeb服务器高级编程
Boxer vs Yellow4
打鸟视频
Rio big adventure
Sora aoi‘s film--Lust fan wall
The Bermuda triangle3
Prostitutes diary
Tram sex maniac 2 (H) rar bag4
delv published in(发表于) 2014/1/6 9:12:42 Edit(编辑)
序列化和反序列化XML应用程序设置类_[Asp.Net教程]

序列化和反序列化XML应用程序设置类_[Asp.Net教程]

序列化和反序列化XML应用程序设置类_[Asp.Net教程]

1 public class ApplicationSettings
2 {
3
4 private bool appSettingsChanged;
5 // 用于存储应用程序设置的变量。
6
7 private Point formLocation;
8
9 public Point FormLocation
10 {
11 get { return formLocation; }
12 set
13 {
14 if (value != formLocation)
15 {
16 formLocation = value;
17 appSettingsChanged = true;
18 }
19 }
20 }
21
22
23 // 从配置文件中反序列化类。
24 public bool LoadAppSettings()
25 {
26 XmlSerializer mySerializer = null;
27 FileStream myFileStream = null;
28 bool fileExists = false;
29
30 try
31 {
32 // 为 ApplicationSettings 类型创建 XmlSerializer。
33 mySerializer = new XmlSerializer(typeof(ApplicationSettings));
34 FileInfo fi = new FileInfo(Application.LocalUserAppDataPath
35 + @"\myApplication.config");
36 // 如果配置文件存在,将其打开。
37 if (fi.Exists)
38 {
39 myFileStream = fi.OpenRead();
40 // 反序列化配置文件以创建新的
41 // ApplicationSettings 实例。
42 ApplicationSettings myAppSettings =
43 (ApplicationSettings)mySerializer.Deserialize(
44 myFileStream);
45 // 为 ApplicationSettings 类的这一实例
46 // 分配属性值。
47 this.formLocation = myAppSettings.FormLocation;
48 fileExists = true;
49 }
50 }
51 catch (Exception ex)
52 {
53 MessageBox.Show(ex.Message);
54 }
55 finally
56 {
57 // 如果 FileStream 是打开的,将其关闭。
58 if (myFileStream != null)
59 {
60 myFileStream.Close();
61 }
62 }
63
64
65 return fileExists;
66 }
67
68 // 如果设置发生变化,则将
69 // 类序列化到配置文件中。
70 public bool SaveAppSettings()
71 {
72 if (this.appSettingsChanged)
73 {
74 StreamWriter myWriter = null;
75 XmlSerializer mySerializer = null;
76 try
77 {
78 // 为 ApplicationSettings 类型
79 // 创建 XmlSerializer。
80 mySerializer = new XmlSerializer(
81 typeof(ApplicationSettings));
82 myWriter =
83 new StreamWriter(Application.LocalUserAppDataPath
84 + @"\myApplication.config", false);
85 // 将 ApplicationSettings 类的这一实例
86 // 序列化到配置文件中。
87 mySerializer.Serialize(myWriter, this);
88 }
89 catch (Exception ex)
90 {
91 MessageBox.Show(ex.Message);
92 }
93 finally
94 {
95 // 如果 FileStream 是打开的,将其关闭。
96 if (myWriter != null)
97 {
98 myWriter.Close();
99 }
100 }
101 }
102 return appSettingsChanged;
103 }
104 }

出处:ting BLOG







添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.