Sorry, I neglected to supply you with means of loading the file back into the object!
VB Code:
Shared Function FromFile(ByVal path As String) As !!YOUR_CLASS_NAME_HERE!! 'this method returns an object loaded from the file specified by path 'if the file path doesn't exist then a new object is created and returned Dim temp As !!YOUR_CLASS_NAME_HERE!! If File.Exists(path) Then Dim binser As BinaryFormatter Dim input As Stream Try 'load the file binser = New BinaryFormatter input = New FileStream(path, FileMode.Open, FileAccess.Read, FileShare.None) 'open the file temp = CType(binser.Deserialize(input), !!YOUR_CLASS_NAME_HERE!!) 'extract instance from stream input.Close() Catch ex As Exception If Not IsNothing(input) Then input.Close() temp = Nothing Return Nothing End Try Else temp = New !!YOUR_CLASS_NAME_HERE!! temp.Path = path End If Return temp End Function
It is a shared function.
so you would use...
...to call it.VB Code:
dim x as MyClass = MyClass.FromFile("Path")![]()




Reply With Quote