/*下面不能把Color属性的值写到 myinfo.config文件中,为什么?*/
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Drawing.Text;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
namespace WebApplication1
{
public partial class WebForm1 : System.Web.UI.Page
{
string fileName = HttpContext.Current.Server.MapPath("~/myinfo.Config"); protected void Page_Load(object sender, EventArgs e)
{
MyInfo myInfo = new MyInfo();
myInfo.Color = Color.Blue;
myInfo.FontStyle = FontStyle.Strikeout | FontStyle.Bold | FontStyle.Italic;
myInfo.Name = "yuna123";
SetMyInfo(myInfo); MyInfo info = GetMyInfo();
Response.Write(info.Name); Response.Write("<br/>");
Response.Write(info.Color); Response.Write("<br/>");
Response.Write(info.FontStyle); Response.Write("<br/>");
}
// 获取信息
public MyInfo GetMyInfo()
{
MyInfo info;
try
{
XmlSerializer serializer = new XmlSerializer(typeof(MyInfo));
FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
info = (MyInfo)serializer.Deserialize(fs);
fs.Close();
}
catch
{
info = new MyInfo();
}
return info;
}
// 设置信息
public void SetMyInfo(MyInfo info)
{
try
{
FileStream stream = new FileStream(this.fileName, FileMode.Create, FileAccess.Write);
XmlSerializer serializer = new XmlSerializer(typeof(MyInfo));
serializer.Serialize(stream, info);
stream.Close();
}
catch { }
}
}
public class MyInfo
{
string _name;
Color _color;
FontStyle _fontStyle;
public string Name
{
get { return this._name; }
set { this._name = value; }
} public Color Color
{
get { return this._color; }
set { this._color = value; }
} public FontStyle FontStyle
{
get { return this._fontStyle; }
set { this._fontStyle = value; }
}
}
}
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Drawing.Text;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
namespace WebApplication1
{
public partial class WebForm1 : System.Web.UI.Page
{
string fileName = HttpContext.Current.Server.MapPath("~/myinfo.Config"); protected void Page_Load(object sender, EventArgs e)
{
MyInfo myInfo = new MyInfo();
myInfo.Color = Color.Blue;
myInfo.FontStyle = FontStyle.Strikeout | FontStyle.Bold | FontStyle.Italic;
myInfo.Name = "yuna123";
SetMyInfo(myInfo); MyInfo info = GetMyInfo();
Response.Write(info.Name); Response.Write("<br/>");
Response.Write(info.Color); Response.Write("<br/>");
Response.Write(info.FontStyle); Response.Write("<br/>");
}
// 获取信息
public MyInfo GetMyInfo()
{
MyInfo info;
try
{
XmlSerializer serializer = new XmlSerializer(typeof(MyInfo));
FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
info = (MyInfo)serializer.Deserialize(fs);
fs.Close();
}
catch
{
info = new MyInfo();
}
return info;
}
// 设置信息
public void SetMyInfo(MyInfo info)
{
try
{
FileStream stream = new FileStream(this.fileName, FileMode.Create, FileAccess.Write);
XmlSerializer serializer = new XmlSerializer(typeof(MyInfo));
serializer.Serialize(stream, info);
stream.Close();
}
catch { }
}
}
public class MyInfo
{
string _name;
Color _color;
FontStyle _fontStyle;
public string Name
{
get { return this._name; }
set { this._name = value; }
} public Color Color
{
get { return this._color; }
set { this._color = value; }
} public FontStyle FontStyle
{
get { return this._fontStyle; }
set { this._fontStyle = value; }
}
}
}
解决方案 »
- Microsoft Visual Studio 2008 安装问题,请大家帮帮我
- imagemap的hotspot热区是否有mouseover事件
- 外部参数用作条件语句进行UPDATE问题
- 关于防止SQL注入的问题
- 请教ASP.net中文本框的数据绑定问题
- 谁能给我一套自助建站的源代码?
- 求合同书!小弟换了个工作,用asp.net做CRM,但要签合同,以下是他们写的合同内容,请帮帮我。
- 如何让一个层(DIV)在一个下拉别表框的上面???
- ie11下出现错误 __dopostback 未定义,请大神们指点指点
- 请问如何判断一个异常为System.Web.HttpException
- asp.net aspx页面转静态html 会的请进
- 菜鸟下拉框问题,高手进
public class MyInfo:ISerializable XmlSerializer xSerial = new XmlSerializer(typeof(MyInfo));
IFormatter formatter = new BinaryFormatter();
Stream stream = new FileStream(@"D:\a.xml", FileMode.Open, FileAccess.Read, FileShare.None);
object obj = formatter.Deserialize(stream);
stream.Close();