HI All
I am trying to send XML structure in the body of mail. I am building the structure using a stringbuilder like this:
Code:
private XmlDocument GenerateXMLForMail(ref DataTable dtMail)
{
xml = new XmlDocument();
StringBuilder sb = new StringBuilder();
sb.Append("<Order>");
sb.Append("<ReferenceNumber>" + string.Empty + "</ReferenceNumber>");
sb.Append("<AssociateId>" + Session["UserID"].ToString() + "</AssociateId>");
sb.Append("<EmployeeName>" + Session["UserName"].ToString().ToUpperInvariant() + "</EmployeeName>");
sb.Append("<OrderTotalValue>" + lblTotal.Text.Trim() + "</OrderTotalValue>");
sb.Append("<PointsRedeemed>" + txtAvlPoints.Text.Trim() + "</PointsRedeemed>");
sb.Append("<Address>" + txtStreetAddress.Text.Trim() + "</Address>");
sb.Append("<City>" + txtCity.Text.Trim() + "</City>");
sb.Append("<State>" + txtState.Text.Trim() + "</State>");
sb.Append("<Country>" + txtCountry.Text.Trim() + "</Country>");
sb.Append("<PinCode>" + txtPINCode.Text.Trim() + "</PinCode>");
sb.Append("<ContactNumber>" + txtContactNo.Text.Trim() + "</ContactNumber>");
sb.Append("<Email>" + txtEmail.Text.Trim() + "</Email>");
sb.Append("<Remarks>" + txtEmail.Text.Trim() + "</Remarks>");
sb.Append("<Products>");
for (int i = 0; i < dtMail.Rows.Count; i++)
{
sb.Append("<Product>");
sb.Append("<Code>" + dtMail.Rows[i]["PRODUCT_CODE"].ToString() + "</Code>");
sb.Append("<Description>" + string.Empty + "</Description>");
sb.Append("<Size>" + string.Empty + "</Size>");
sb.Append("<Quantity>" + "1" + "</Quantity>");
sb.Append("<Price>" + dtMail.Rows[i]["RATE"].ToString() + "</Price>");
sb.Append("</Product>");
}
sb.Append("</Products>");
sb.Append("</Order>");
xml.LoadXml(sb.ToString());
return xml;
}
It is successfully converting into XML and then i am assigning xml value to a string variable like this ---
Code:
strBodyText = xml.InnerXml;
After that mail is being sent. I had made the property IsBodyHtml = false. The mail is going in text format. Now the thing is the xml should go in a proper format with its nodes clearly visible, like well formed xml.
What changes i need to do in my code to achieve this feature. What else i need to do to improve the code?
-- Abhishek
