We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

replace text in a WordDocument by an hyperlink ?


I am currently using: mydoc.Replace("this", "bythat", false, false);

--> But how to replace "this" by an hyperlink ?


3 Replies

SR Suganya Rathinam Syncfusion Team April 25, 2016 06:22 AM UTC

Hi Fabrice,

Thank you for contacting Syncfusion support.

DocIO provides support to replace the text with a new
TextBodyPart. The hyperlink can be placed inside the paragraph of a TextBodyPart which can be used to replace the text in the document. Please find the following code snippets for your requirement and let us know if it helps.

WordDocument document = new WordDocument(FileName); 
//Create a new paragraph  
WParagraph paragraph = new WParagraph(document); 
//Append hyperlink to the paragraph 
paragraph.AppendHyperlink("http://help.syncfusion.com/file-formats/docio/overview", "DocIO UG", HyperlinkType.WebLink); 
//Create new TextBodyPart and add the paragraph to it 
TextBodyPart textBodyPart = new TextBodyPart(document); 
//Replace the text with the TextBodyPart 
document.Replace("this", textBodyPart, false, true); 
//Save and close the document 
document.Save(FileName, FormatType.Docx); 

Please find the following UG documentation link on Find and Replace functionality for more details.


FF fff April 26, 2016 11:20 AM UTC

That's great, giving huge flexibility, with more than just hyperlinks (not so obvious in the sf docs :) )

tanks a lot Suganya


SR Suganya Rathinam Syncfusion Team April 27, 2016 05:16 AM UTC

Hi Fabrice,

Thank you for your feedback. Please get back to us if you need any further assistance.


Live Chat Icon For mobile
Up arrow icon