/ Published in: VB.NET
Serializes any object and writes it to the specified location on the disk.
Example:
Dim obj As DataTable
'save obj to disk
SerializeToFile(filepath, obj)
'to read it back, use DirectCast
Dim obj2 As DataTable = DirectCast(My.Computer.FileSystem.ReadAllBytes(filepath), DataTable)
Example:
Dim obj As DataTable
'save obj to disk
SerializeToFile(filepath, obj)
'to read it back, use DirectCast
Dim obj2 As DataTable = DirectCast(My.Computer.FileSystem.ReadAllBytes(filepath), DataTable)
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
'serialize an object to a file Public Shared Sub SerializeToFile(ByVal path As String, ByVal data As Object) Try Dim BF As New System.Runtime.Serialization.Formatters.Binary.BinaryFormatter() Dim MS As New System.IO.MemoryStream() BF.Serialize(MS, data) My.Computer.FileSystem.WriteAllBytes(path, MS.GetBuffer(), False) Catch ex As Exception Throw ex End Try End Sub