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
close icon

replace text in a WordDocument by an hyperlink ?

Hi,

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

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

Thanks,
F

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); 
textBodyPart.BodyItems.Add(paragraph); 
//Replace the text with the TextBodyPart 
document.Replace("this", textBodyPart, false, true); 
//Save and close the document 
document.Save(FileName, FormatType.Docx); 
document.Close(); 

Please find the following UG documentation link on Find and Replace functionality for more details.
http://help.syncfusion.com/file-formats/docio/working-with-find-and-replace

Regards,
Suganya



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

BR,
Fabrice



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.

Regards,
Suganya


Loader.
Live Chat Icon For mobile
Up arrow icon