Best Practice for LastModifiedUser and LastModifiedDate fields in a BO


Best Practice for LastModifiedUser and LastModifiedDate fields in a BO...
Author
Message
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.3K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Way too easy...



Now, how do I get byte array back into the object via deserialization? Or probably more to the point, how do I turn the array into a memory stream?
Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
Here is an example if you have a file saved to disk.  In the auditing sample, the byte array will be given back to you through the delegate, so you would skip the part of loading the byte array.

Dim formatter As New System.Runtime.Serialization.Formatters.Binary.BinaryFormatter()
Dim inStream As New System.IO.MemoryStream()
Dim inBytes As Byte() = System.IO.File.ReadAllBytes("c:\MySerializedFil.bin")
Dim MyBO As MyBoType

'-- Move the byte array into a stream
inStream.Write(inBytes, 0, inBytes.Length)

'-- Deserialize the object
MyBO = CType(formatter.Deserialize(inStream), MyBOType)

Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.3K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Thanks! I'm not too familiar with the IO class and streams. I was having trouble getting the byte array into the stream. Again not too hard once you understand it! BigGrin
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.3K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Thanks for the help I got it working. However I had to wrap the deserialize call in a try/catch as it always threw an serializationexceptions:

'-- Function to return the appropriate object from an array of bytes.

Private Function GetItem(data As Byte()) As TestSerializableItem

Dim formatter As New System.Runtime.Serialization.Formatters.Binary.BinaryFormatter()

using inStream As New System.IO.MemoryStream()



'-- used a test class that had the Serializable attribute set

Dim myItem As TestSerializableItem



'-- Move the byte array into a stream

inStream.Write(data, 0, data.Length)



'-- Deserialize the object. This always

Try

myItem = CType(formatter.Deserialize(inStream), TestSerializableItem)

Catch ex As Exception

End Try

End Using



Return myItem

End Function

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search