Aug 31, 2015 11:08 PM|cnranasinghe|LINK
Hope you can adapt the below code for your requirement, code below turns an object into xml document and put it on memory stream.
on the click event
Dim currentStream As New MemoryStream()
Dim streamWriter As New StreamWriter(currentStream)
currentStream.Position = 0
Now the "currentStream" contains xml document content as string, Here "reportDetail" is the object which needed to converted to xml. alter this function as to your requirement.
Public Shared Function CreateXMLDoc(ByVal value As Object) As String
Dim rv As String = ""
Dim xml = New XmlSerializer(value.[GetType]())
Using memoryStream As MemoryStream = New MemoryStream()
Using xmlWriter As XmlTextWriter = New XmlTextWriter(memoryStream, Encoding.UTF8)
xmlWriter.Formatting = Formatting.Indented
rv = Encoding.UTF8.GetString(memoryStream.ToArray())
you can use the currentStream variable to manipulate the xml, like sending an email with xml attachment.