Rediger

Del via


SessionStateItemCollection.Serialize(BinaryWriter) Method

Definition

Writes the contents of the collection to a BinaryWriter.

public:
 void Serialize(System::IO::BinaryWriter ^ writer);
public void Serialize (System.IO.BinaryWriter writer);
member this.Serialize : System.IO.BinaryWriter -> unit
Public Sub Serialize (writer As BinaryWriter)

Parameters

writer
BinaryWriter

The BinaryWriter used to write the serialized collection to a stream or encoded string.

Examples

The following code example creates and populates a SessionStateItemCollection collection and writes the contents to a file using the Serialize method.

SessionStateItemCollection items = new SessionStateItemCollection();

items["LastName"] = "Wilson";
items["FirstName"] = "Dan";

System.IO.BinaryWriter writer = new System.IO.BinaryWriter(
  System.IO.File.Open(Server.MapPath("session_collection.bin"), System.IO.FileMode.Create));

items.Serialize(writer);

writer.Close();
Dim items As SessionStateItemCollection = New SessionStateItemCollection()

items("LastName") = "Wilson"
items("FirstName") = "Dan"

Dim writer As System.IO.BinaryWriter = New System.IO.BinaryWriter( _
  System.IO.File.Open(Server.MapPath("session_collection.bin"), System.IO.FileMode.Create))

items.Serialize(writer)

writer.Close()

Remarks

The Serialize method can be used to write the contents of a SessionStateItemCollection collection to the session store.

To retrieve a serialized SessionStateItemCollection object from the session store, use the Deserialize method.

Applies to

See also