Copying message properties

Hi,

Cna we copy a message’s complete properties set to a new message fro duplication? I can not find any such method.

Hi Aaron,

Thank you for posting your query.

You need to copy the properties and mapping one by one as shown in the following code sample. Please try it at your end and share your feedback with us if this doesn’t meet your requirements.

Code:

// Load a working Task request
MapiMessage msg = MapiMessage.FromFile("MSOutlook-TR.msg");
MapiMessage newMsg= new MapiMessage();

// Create a brand new Task instance
MapiTask mytask = new MapiTask();

// Copy properties
foreach (DictionaryEntry entry in task.Properties)
{
    mytask.Properties.Add(entry.Key, entry.Value);
}

// Copy mapping
MapiNamedPropertyMappingStorage storage = task.NamedPropertyMapping;
foreach (DictionaryEntry entry in storage.Properties) {
    mytask.NamedPropertyMapping.Properties.Add(entry.Key, entry.Value);
}

Console.WriteLine(mytask.NamedPropertyMapping.Properties.Count);
Console.WriteLine(task.NamedPropertyMapping.Properties.Count);

newMsg.Save("Cool.msg");