Hi team ,
we are trying to get all Mapi Message properties from MSG file ( subject , from , to , cc , body , date , …)
and save it on an xml document using this code :
//- Load the .MSG File
MapiMessage message = MapiMessage.FromFile(EmailFilePath);
//- Create an XML Document
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.LoadXml(“”);
//- Encode the XML Document in ASCII with his declaration
XmlDeclaration xmlDec;
xmlDec = xmlDocument.CreateXmlDeclaration(“1.0”, “UTF-8”, “yes”);
//- Create the “Properties” element in the XML Document
XmlElement xPropertiesElement = xmlDocument.CreateElement(“Properties”);
xmlDocument.DocumentElement.AppendChild(xPropertiesElement);
MapiPropertyCollection MapiProp = message.NamedProperties;
foreach (MapiNamedProperty namedProperty in MapiProp.Values)
{
string propertyValue = namedProperty.ToString();
XmlElement xElement = xmlDocument.CreateElement(“Property”);
xPropertiesElement.AppendChild(xElement);
XmlAttribute xmlAttributeName = xmlDocument.CreateAttribute(“Name”);
xmlAttributeName.Value = (namedProperty.Name);
xElement.Attributes.Append(xmlAttributeName);
XmlAttribute xmlAttributeValue = xmlDocument.CreateAttribute(“Value”);
xmlAttributeValue.Value = (propertyValue);
xElement.Attributes.Append(xmlAttributeValue);
}
but we don’t get the desired result:
we get something like this :
< Properties>
< Property Name=“__substg1.0_8000001F” Value=“exemple@gmail.com” />
< Property Name=“” Value=“False” />
< Property Name=“” Value=“0” />
…
< /Properties>
< /Email>
Is there a problem with our code ? or another way to do it ?
we have tried to do it with a similar code and it worked :
MapiPropertyCollection properties = mapiMsg.NamedProperties;
foreach (MapiProperty mapiProp in properties.Values)
{
XmlElement xSubjectElement = xmlDocument.CreateElement("Property");
xPropertiesElement.AppendChild(xSubjectElement);
XmlAttribute xmlAttributeSubjectN = xmlDocument.CreateAttribute("Name");
xmlAttributeSubjectN.Value = ("Subject");
xSubjectElement.Attributes.Append(xmlAttributeSubjectN);
XmlAttribute xmlAttributeSubjectV = xmlDocument.CreateAttribute("Value");
xmlAttributeSubjectV.Value = (mapiMsg.Subject);
xSubjectElement.Attributes.Append(xmlAttributeSubjectV);
// Same code for all properties which is not an optimized code
}
Could you please provide example code to get all mapi property at once