Querying message bodies
To find a specific message body, you use the NewslettersManager class. The following code finds a message body with the specified Idthrough the Native API.
public MessageBody QueryMessageBody(Guid id)
{
NewslettersManager manager = NewslettersManager.GetManager();
MessageBody messageBody = manager.GetMessageBodies().Where(b => b.Id == id).SingleOrDefault();
return messageBody;
}
First, you initialize the NewslettersManager. Then, you call GetMessageBodies to retrieve all message bodies and, finally, you filter the message bodies based on the Id property.
TIP: You can filter by any of the MessageBody properties.
Another way is to use the GetMessageBody method of the manager class:
public MessageBody QueryMessageBody(Guid id)
{
NewslettersManager manager = NewslettersManager.GetManager();
MessageBody messageBody = null;
try
{
messageBody = manager.GetMessageBody(id);
}
catch (ItemNotFoundException e)
{
//implement logic regarding the missing item.
}
return messageBody;
}
NOTE: If no message body with the specified ID exists, the GetMessageBody method throwsTelerik.Sitefinity.SitefinityExceptions.ItemNotFoundException exception.