System. Data;
System. Configuration;
System. Web;
System. Web. Security;
System. Web. UI;
System. Web. UI. WebControls;
System. Web. UI. WebControls. WebParts;
System. Web. UI. HtmlControls;
UsingSystem. IO;
System. Runtime. Serialization. Formatters. Binary;
ClassToSerialize
Id =;
Name =;
Sex =;
ClassToSerialize ();
FileStream (, FileMode. Create );
BinaryFormatter ();
DeSerializeNow ()
ClassToSerialize ();
;
FileStream (, FileMode. Open, FileAccess. Read, FileShare. Read );
BinaryFormatter ();
ClassToSerialize;
Response. Write (c. name );
System. Data;
System. Configuration;
System. Web;
System. Web. Security;
System. Web. UI;
System. Web. UI. WebControls;
System. Web. UI. WebControls. WebParts;
System. Web. UI. HtmlControls;
UsingSystem. Xml. Serialization;
Person
Name;
Name
Name;
Sex;
Age =;
Course [] Courses;
Person ()
Person (Name)
;
Course
Name;
Description;
Course ()
Course (name, description)
Person ();
Course [];
] = Course (,);
] = Course (,);
XmlSerializer (Person ));
FileStream (, FileMode. Create, FileAccess. Write, FileShare. Read );
XMLDeserialize ()
XmlSerializer (Person ));
FileStream (, FileMode. Open, FileAccess. Read, FileShare. Read );
Person;
]. Name );
]. Description );
]. Name );
]. Description );
Xmlns: xsd =>
</Age>
System. Data;
System. Configuration;
System. Web;
System. Web. Security;
System. Web. UI;
System. Web. UI. WebControls;
System. Web. UI. WebControls. WebParts;
System. Web. UI. HtmlControls;
System. Runtime. Serialization;
System. Runtime. Serialization. Formatters. Binary;
Employee: ISerializable
EmpId =;
EmpName =;
NoSerialString =;
Employee ()
Employee (SerializationInfo info, StreamingContext ctxt)
) Info. GetValue (,());
,());
GetObjectData (SerializationInfo info, StreamingContext ctxt)
, EmpId );
, EmpName );
Employee ();
;
;
;
, FileMode. Create );
BinaryFormatter ();
);
;
, FileMode. Open );
BinaryFormatter ();
);
Employee mp2 = (Employee) bf2.Deserialize (steam2 );
Steam2.Close ();
Response. Write (mp2.EmpId );
Response. Write (mp2.EmpName );
Response. Write (mp2.NoSerialString );
}
Http://www.cnblogs.com/goody9807/archive/2012/02/27/2369832.html