Click here to Skip to main content
15,893,644 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I am having a document which has several bookmarks. Each bookmark may contain some text either plain text or formatted text(HTML). Now The text for each bookmark is extracted from database. And I download the document. I made several changes such as changing font color, font size and underline the font etc.,. Then I extract each bookmark text to database and I update each column where from I got the previous value for the respective bookmark. After the updation, Again I load the document with updated formatted text but I only got the plain text instead of formatted text.

For Example I have 3 bookmarks in a document
Name: Vinoth whose bookmark.Text is <b>Vinoth</b>
City: Chennai whose bookmark.Text is <u>Chennai</u>
Country: India whose bookmark.Text is <font size='5'>India</font>
I used DocumentBuilder.MoveToBookmark(Bookmark.Name) and InsertHtml(Bookmark.Text) to get the document with formatted text and I download the document.

Now I am updating the formatted text in the downloaded document as follows
Name: Vinoth -font size has changed
City: Chennai-font fore color has changed and underline is removed
Counrty: India-font style has changed

After making changes in the formatted text I update all the bookmark texts to database using c# coding.I can save all bookmark's text as plain text to database. Again I am loading the document with updated formatted text. But I only got plain text in resultant document as follows
Name: Vinoth
City: Chennai
Country: India
Could you tell me the solution to get the updated formatted text in the bookmark's text using c#.

string text = doc.FirstSection.Body.ToString(SaveFormat.Html);

reads all the text into a single string variable. I need each bookmark text in individual string variable.
Posted
Updated 5-Aug-14 12:14pm
v2
Comments
Sergey Alexandrovich Kryukov 5-Aug-14 18:37pm    
Not clear. What is the type of your document, its format, etc.?
—SA
Vino_ 5-Aug-14 18:56pm    
It is MS word document 2010.
Vino_ 5-Aug-14 18:48pm    
It is MS word document 2010.
Vino_ 5-Aug-14 18:59pm    
Whatever changes I made in the document such as changing font size, font color, style should be updated in the database. Each Bookmark's text is loaded from database. After updation the changes should be reflected in the document.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900