Loads a message from XML stream using the specified XmlTextReader object.
true if the message was successfully loaded from the XML stream; otherwise, false.
This method can loada a message which was previously serialized using Serialize method.
| Exception Type | Condition |
|---|---|
| MailBeeInvalidArgumentException | xmlReader is a null reference (Nothing in Visual Basic). |
| MailBeeIOException | An I/O error occurred and the ThrowExceptions property is true. |
This sample loads the message from .EML file, saves it into .XML file, and then loads this message back from the .XML file.
[C#] using System; using System.Xml; using System.IO; using MailBee; using MailBee.Mime; class Sample { static void Main(string[] args) { // Load the message from file. MailMessage msg = new MailMessage(); msg.LoadMessage(@"C:\Docs\msg.eml"); // Display the subject of the message and // save this message to .XML file. Console.WriteLine(msg.Subject); msg.Serialize(@"C:\Temp\msg.xml"); XmlTextReader reader = null; try { // Open .XML file for reading. reader = new XmlTextReader(File.OpenRead(@"C:\Temp\msg.xml")); // Load the message from .XML file. MailMessage newMsg = new MailMessage(); newMsg.Deserialize(reader); // Display the subject of the message. Console.WriteLine(newMsg.Subject); } finally { if (reader != null) reader.Close(); } } }
[Visual Basic] Imports System Imports System.IO Imports System.Xml Imports MailBee Imports MailBee.Mime Module Sample Sub Main(ByVal args As String()) ' Load the message from file. Dim msg As New MailMessage msg.LoadMessage("C:\Docs\msg.eml") ' Display the subject of the message and ' save this message to .XML file. Console.WriteLine(msg.Subject) msg.Serialize("C:\Temp\msg.xml") Dim reader As XmlTextReader = Nothing Try ' Open .xml file for reading. reader = New XmlTextReader(File.OpenRead("C:\Temp\msg.xml")) ' Load the message from .XML file. Dim newMsg As New MailMessage newMsg.Deserialize(reader) ' Display the subject of the message. Console.WriteLine(newMsg.Subject) Finally If Not reader Is Nothing Then reader.Close() End Try End Sub End Module
MailMessage Class | MailBee.Mime Namespace | MailMessage.Deserialize Overload List