Hi
Maybe you can use this?
VB Code:
Private st As IO.MemoryStream 'The stream to hold the data
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Serializes the class to a memorystream.
Dim mc As New MyClassToSerialize()
st = New IO.MemoryStream()
mc.A = 1
mc.B = 2
mc.C = 3
mc.Save(st)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
'De-serializes the class from the memorystream
Dim mc As MyClassToSerialize
mc = MyClassToSerialize.Load(st)
MsgBox(mc.A)
MsgBox(mc.B)
MsgBox(mc.C)
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
'Loads the serialized class as XML text.
Dim S As String
S = MyClassToSerialize.LoadToXML(st)
MsgBox(S)
End Sub
'The class to serialize.
<Serializable()> Public Class MyClassToSerialize
Public A As Integer
Public B As Integer
Public C As Integer
Public Sub Save(ByVal st As IO.Stream)
Dim xml As New Xml.Serialization.XmlSerializer(GetType(MyClassToSerialize))
st.Position = 0
xml.Serialize(st, Me)
End Sub
Public Shared Function Load(ByVal st As IO.Stream) As MyClassToSerialize
Dim xml As New Xml.Serialization.XmlSerializer(GetType(MyClassToSerialize))
Dim mcts As MyClassToSerialize
st.Position = 0
mcts = DirectCast(xml.Deserialize(st), MyClassToSerialize)
Return mcts
End Function
Public Shared Function LoadToXML(ByVal st As IO.Stream) As String
Dim xml As New Xml.XmlDocument()
st.Position = 0
xml.Load(st)
Return xml.OuterXml
End Function
End Class