MapiMessage.RemoveAttachments

MapiMessage.RemoveAttachments method

Removes all attachments from an MSG file, overwrites the file, and returns the removed attachments.

public static MapiAttachmentCollection RemoveAttachments(string path)
ParameterTypeDescription
pathStringThe path of the MSG file.

Return Value

The removed attachments.

Exceptions

exceptioncondition
ArgumentNullExceptionpath is null.
ArgumentExceptionpath is empty.

Examples

This example removes the attachments from an MSG file and saves them to disk.

[C#]

MapiAttachmentCollection attachments = MapiMessage.RemoveAttachments(@"c:\messages\message.msg");

foreach (MapiAttachment attachment in attachments)
{
    Console.WriteLine("Attachment: " + attachment.LongFileName);
    attachment.Save(Path.Combine(@"c:\attachments", attachment.LongFileName));
}

[Visual Basic]

Dim attachments As MapiAttachmentCollection = MapiMessage.RemoveAttachments("c:\messages\message.msg")

For Each attachment As MapiAttachment In attachments
    Console.WriteLine("Attachment: " + attachment.LongFileName)
    attachment.Save(Path.Combine("c:\attachments", attachment.LongFileName))
Next

See Also