MailBee.NET Objects 3.1

MailMessage.Deserialize Method (String)

Loads a message from the specified .XML file.

public bool Deserialize(
   string filename
);

Parameters

filename
A string containing the name of the .XML file.

Return Value

true if the message was successfully loaded from .XML file; otherwise, false.

Remarks

This method can load a message which was previously saved using Serialize method.

Exceptions

Exception Type Condition
MailBeeInvalidArgumentException filename is a null reference (Nothing in Visual Basic) or an empty string.
MailBeeIOException An I/O error occurred and ThrowExceptions is true.

Example

This sample loads the message from .EML file, saves it to .XML file, and loads this message back from .XML file.

[C#]
using System;
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\TestMail.eml");

        // Display the subject of this message.
        Console.WriteLine(msg.Subject);

        // Save the message to .XML file.
        msg.Serialize(@"C:\Temp\msg.xml");

        // Load the message from .XML file and display
        // the subject of this message.
        MailMessage newMsg = new MailMessage();
        newMsg.Deserialize(@"C:\Temp\msg.xml");
        Console.WriteLine(newMsg.Subject);
    }
}
[Visual Basic]
Imports System
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\TestMail.eml")

        ' Display the subject of this message.
        Console.WriteLine(msg.Subject)

        ' Save the message to .XML file.
        msg.Serialize("C:\Temp\msg.xml")

        ' Load the message from .XML file and display
        ' the subject of this message.
        Dim newMsg As New MailMessage
        newMsg.Deserialize("C:\Temp\msg.xml")
        Console.WriteLine(newMsg.Subject)
    End Sub
End Module

See Also

MailMessage Class | MailBee.Mime Namespace | MailMessage.Deserialize Overload List