Author |
|
Terryc Newbie
Joined: 10 November 2008 Location: United States
Online Status: Offline Posts: 2
|
Posted: 10 November 2008 at 2:36pm | IP Logged
|
|
|
How can the contentEditable attribute, with a div tag, be added to the HTML message stream so an HTML message can be edited for a reply in a winform using the webcontrol object?
|
Back to Top |
|
|
Andrew AfterLogic Support
Joined: 28 April 2006 Location: United States
Online Status: Offline Posts: 1189
|
Posted: 11 November 2008 at 6:03am | IP Logged
|
|
|
The complexity is that HTML messages may contain full HTML document with <!DOCTYPE>, <HTML>, <HEAD>, etc. Placing such HTML into a <DIV> would not allow you to display the document correctly.
There are two possible ways:
- remove everything except contents of <BODY></BODY> tag and place it inside a <DIV></DIV>;
- place <DIV></DIV> inside <BODY></BODY>.
In both the cases, MailBee.Html namespace would be useful to you. The following sample implements the second approach:
Code:
using MailBee;
using MailBee.Mime;
using MailBee.Html;
MailMessage msg = new MailMessage();
msg.LoadMessage(@"D:\test.eml");
Processor htmlProcessor = new MailBee.Html.Processor();
// Assign HTML body from the message to HtmlProcessor
htmlProcessor.Dom.OuterHtml = msg.GetHtmlAndSaveRelatedFiles();
if (htmlProcessor.Dom.GetInnerElementsByName("BODY").Count > 0)
{
// Get reference to <BODY></BODY> element
Element bodyElement = htmlProcessor.Dom.GetInnerElementsByName("BODY")[0];
// Create new <DIV> element
Element divElement = new Element("<div contentEditable=\"true\"></div>");
// Copy all contents of <BODY> to the <DIV>
foreach (Element elem in bodyElement.InnerElements)
{
divElement.InnerElements.Add(elem);
}
// Remove all <BODY> subelements
bodyElement.InnerElements.RemoveAll( );
// Add <DIV> to <BODY>
bodyElement.InnerElements.Add(divEle ment);
// Get the resulting HTML
string str = htmlProcessor.Dom.OuterHtml;
webBrowser1.DocumentText = str;
}
else
{
MessageBox.Show("Message doesn't contain BODY tag");
} |
|
|
Best regards,
Andrew
|
Back to Top |
|
|