To be honest, I am surprised that nobody has suggested using serialization. You can use simple XML serialization to convert your class into an XML file or convert your List(Of Contacts) into a single XML file with multiple nodes. Take a look at this example:
Fiddle: https://dotnetfiddle.net/FevTtrCode:Option Strict On Imports System Imports System.Collections.Generic Imports System.Xml.Serialization Public Module Module1 Public Sub Main() Dim dday9 As New Contact With {.FirstName = "dday", .LastName = "9", .PhoneNumber = "555-555-1234", .DateOfBirth = New Date(1991, 08, 12)} Dim dday10 As New Contact With {.FirstName = "dday", .LastName = "10", .PhoneNumber = "985-555-1234", .DateOfBirth = Date.Now} Dim collection As New List(Of Contact) From {dday9, dday10} For Each value As Contact In collection Contact.Serialize(value, String.Format("{0}{1}.xml", value.FirstName, value.LastName)) Next End Sub End Module Public Class Contact Private _firstName As String Public Property FirstName As String Get Return _firstName End Get Set(ByVal value As String) If _firstName <> value Then _firstName = value Me.OnFirstNameChanged() End If End Set End Property Private _lastName As String Public Property LastName As String Get Return _lastName End Get Set(ByVal value As String) If _lastName <> value Then _lastName = value Me.OnLastNameChanged() End If End Set End Property Private _phoneNumber As String Public Property PhoneNumber As String Get Return _phoneNumber End Get Set(ByVal value As String) If _phoneNumber <> value Then _phoneNumber = value Me.OnPhoneNumberChanged() End If End Set End Property Private _dateOfBirth As Date Public Property DateOfBirth As Date Get Return _dateOfBirth End Get Set(ByVal value As Date) If _dateOfBirth <> value Then _dateOfBirth = value Me.OnDateOfBirthChanged() End If End Set End Property Protected Overridable Sub OnFirstNameChanged() RaiseEvent FirstNameChanged(Me, EventArgs.Empty) End Sub Protected Overridable Sub OnPhoneNumberChanged() RaiseEvent PhoneNumberChanged(Me, EventArgs.Empty) End Sub Protected Overridable Sub OnLastNameChanged() RaiseEvent LastNameChanged(Me, EventArgs.Empty) End Sub Protected Overridable Sub OnDateOfBirthChanged() RaiseEvent DateOfBirthChanged(Me, EventArgs.Empty) End Sub Public Event FirstNameChanged(ByVal sender As Object, ByVal e As EventArgs) Public Event LastNameChanged(ByVal sender As Object, ByVal e As EventArgs) Public Event PhoneNumberChanged(ByVal sender As Object, ByVal e As EventArgs) Public Event DateOfBirthChanged(ByVal sender As Object, ByVal e As EventArgs) Public Shared Function Deserialize(ByVal path As String) As Contact Dim sender As Contact Dim serializer As New XmlSerializer(GetType(Contact)) Using reader As IO.StreamReader = New IO.StreamReader(path) sender = DirectCast(serializer.Deserialize(reader), Contact) End Using Return sender End Function Public Shared Sub Serialize(ByVal sender As Contact, ByVal path As String) Dim serializer As New XmlSerializer(GetType(Contact)) Dim xml As String = String.Empty Using w As IO.StringWriter = New IO.StringWriter() serializer.Serialize(w, sender) End Using End Sub End Class




Reply With Quote