StrataFrame Forum
Back
Login
Login
Home
»
StrataFrame Application Framework - V1
»
Business Objects and Data Access (How do I?)
»
Best Practice for LastModifiedUser and LastModifiedDate fields in a BO...
Best Practice for LastModifiedUser and LastModifiedDate fields in a BO
Post Reply
Like
3
Prev
1
2
Jump To Page
Best Practice for LastModifiedUser and LastModifiedDate fields in a BO...
View
Flat Ascending
Flat Descending
Threaded
Options
Subscribe to topic
Print This Topic
RSS Feed
Goto Topics Forum
Author
Message
Greg McGuffey
Greg McGuffey
posted 16 Years Ago
ANSWER
Post Details
Share Post
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?
Reply
Like
2
Trent Taylor
Trent Taylor
posted 16 Years Ago
ANSWER
Post Details
Share Post
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)
Reply
Like
2
Greg McGuffey
Greg McGuffey
posted 16 Years Ago
ANSWER
Post Details
Share Post
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!
Reply
Like
2
Greg McGuffey
Greg McGuffey
posted 16 Years Ago
ANSWER
Post Details
Share Post
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
Reply
Like
1
GO
Merge Selected
Merge into selected topic...
Merge into merge target...
Merge into a specific topic ID...
Open Merge
Post Reply
Like
3
Prev
1
2
Jump To Page
Similar Topics
Post Quoted Reply
Reading This Topic
Login
Login
Remember Me
Reset Password
Resend Validation Email
Login
Explore
Messages
Mentions
Search