Regarding MailItem.Body Property

B

Bharathi

Hi,

I am trying to access few fields(To, From, Body, Subject) in an
outlook email in my code, using C#.net. I am creating an xml file
which contains values of the above mentioned fields.


When an outlook email contains any attachment, then while accessing
"MailItem.Body" property, The system hangs and the CPU usuage goes to
100%.


Please let me know how would i resolve this issue

Regards,
Bharathi
 
K

Ken Slovak - [MVP - Outlook]

Attachments should not affect reading Body. Show your code and tell us what
version of Outlook and what version of VS and the Framework.
 
B

Bharathi

Hi,

I am using Microsoft Outlook 2003. VS 2005.

I have created a "Shared Add in" project

I have coded a method called "" as followed:

private void CreateXML(MailItem mi)
{
XmlTextWriter textWriter = new
XmlTextWriter("C:\\myXmFile.xml", null);

textWriter.WriteStartDocument();

// Write comments
textWriter.WriteComment("This xml document stores the xml format
of the selected outlook mail");

textWriter.WriteStartElement("Mail");

textWriter.WriteStartElement("To");
textWriter.WriteString(mi.To.ToString());
textWriter.WriteEndElement();

textWriter.WriteStartElement("From");
textWriter.WriteString(mi.SenderName.ToString());
textWriter.WriteEndElement();

textWriter.WriteStartElement("Subject");
textWriter.WriteString(mi.Subject.ToString());
textWriter.WriteEndElement();


textWriter.WriteStartElement("Body");
textWriter.WriteString(mi.Body.ToString());
textWriter.WriteEndElement();

textWriter.WriteEndElement();

//WriteEndDocument methods close a document after writing
textWriter.WriteEndDocument();

textWriter.Close();
}

In the above method, If the MailItem contains any attachments,then the
system would hang and the CPU usage goes to 100% while processing the
following line of code:
"textWriter.WriteString(mi.Body.ToString());"

I am unable to understand why this is happening.

Bharathi
 
K

Ken Slovak - [MVP - Outlook]

That's very odd. Try not using ToString(), Body is already a string. Other
than that I have no idea. I've never seen anything like that here.
 
Top