I am getting the HTML, by pulling the original contents of the bookmark using the GetHTMLFromBookmark function which I found on the forums(see code below).
This returns a HTML string(see below).
What I need to do is - 1 - pull the text from a bookmark. 2 - allow user on the web to edit this text(this is done on a webpage, using FreeTextBox, and works nicely). 3 - insert the updated HTML back into the document.
How would I go about doing this, so that the formatting of the final document looks ok, without getting messed up?
HTML String returned:
String BodyHTML = @"
May 19, 2008
Dr. Jay Vida
Lakewood , NJ 08701
Re: Last, First
Dear
Many thanks for this kind referral.
Sincerely,
";
private static string GetHtmlFromBookmark(string bookmarkName, Document doc, SaveFormat ThisSaveFormat)
{
Document docClone = doc.Clone();
Document doc1 = new Document();
Bookmark mark = docClone.Range.Bookmarks[bookmarkName];
Node node = mark.BookmarkStart.ParentNode;
Node endNode = mark.BookmarkEnd.ParentNode.NextSibling;
while (!node.Equals(endNode))
{
if ((node as CompositeNode).ChildNodes.Contains(mark.BookmarkStart))
{
Node child = (node as CompositeNode).FirstChild;
Node endChild = mark.BookmarkStart.NextSibling;
while (!child.Equals(endChild))
{
child = child.NextSibling;
child.PreviousSibling.Remove();
}
}
if ((node as CompositeNode).ChildNodes.Contains(mark.BookmarkEnd))
{
Node child = mark.BookmarkEnd;
while (!child.Equals(child.ParentNode.LastChild))
{
child = child.NextSibling;
child.PreviousSibling.Remove();
}
child.Remove();
}
doc1.FirstSection.Body.AppendChild(doc1.ImportNode(node, true, ImportFormatMode.KeepSourceFormatting));
node = node.NextSibling;
if (node == null)
break;
}
MemoryStream stream = new MemoryStream();
doc1.Save(stream, ThisSaveFormat);
string html = Encoding.UTF8.GetString(stream.GetBuffer());
return html;
}