diff --git a/Paragraphs/Replace-text-with-bookmark-hyperlink/.NET/Replace-text-with-bookmark-hyperlink.slnx b/Paragraphs/Replace-text-with-bookmark-hyperlink/.NET/Replace-text-with-bookmark-hyperlink.slnx new file mode 100644 index 00000000..3f139b45 --- /dev/null +++ b/Paragraphs/Replace-text-with-bookmark-hyperlink/.NET/Replace-text-with-bookmark-hyperlink.slnx @@ -0,0 +1,3 @@ + + + diff --git a/Paragraphs/Replace-text-with-bookmark-hyperlink/.NET/Replace-text-with-bookmark-hyperlink/Data/Template.docx b/Paragraphs/Replace-text-with-bookmark-hyperlink/.NET/Replace-text-with-bookmark-hyperlink/Data/Template.docx new file mode 100644 index 00000000..06ac6103 Binary files /dev/null and b/Paragraphs/Replace-text-with-bookmark-hyperlink/.NET/Replace-text-with-bookmark-hyperlink/Data/Template.docx differ diff --git a/Paragraphs/Replace-text-with-bookmark-hyperlink/.NET/Replace-text-with-bookmark-hyperlink/Output/.gitkeep b/Paragraphs/Replace-text-with-bookmark-hyperlink/.NET/Replace-text-with-bookmark-hyperlink/Output/.gitkeep new file mode 100644 index 00000000..5f282702 --- /dev/null +++ b/Paragraphs/Replace-text-with-bookmark-hyperlink/.NET/Replace-text-with-bookmark-hyperlink/Output/.gitkeep @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Paragraphs/Replace-text-with-bookmark-hyperlink/.NET/Replace-text-with-bookmark-hyperlink/Output/Result.docx b/Paragraphs/Replace-text-with-bookmark-hyperlink/.NET/Replace-text-with-bookmark-hyperlink/Output/Result.docx new file mode 100644 index 00000000..f4bf6bc9 Binary files /dev/null and b/Paragraphs/Replace-text-with-bookmark-hyperlink/.NET/Replace-text-with-bookmark-hyperlink/Output/Result.docx differ diff --git a/Paragraphs/Replace-text-with-bookmark-hyperlink/.NET/Replace-text-with-bookmark-hyperlink/Program.cs b/Paragraphs/Replace-text-with-bookmark-hyperlink/.NET/Replace-text-with-bookmark-hyperlink/Program.cs new file mode 100644 index 00000000..9b692e0f --- /dev/null +++ b/Paragraphs/Replace-text-with-bookmark-hyperlink/.NET/Replace-text-with-bookmark-hyperlink/Program.cs @@ -0,0 +1,39 @@ +using Syncfusion.DocIO; +using Syncfusion.DocIO.DLS; + +namespace Replace_text_with_bookmark_hyperlink +{ + class Program + { + static void Main(string[] args) + { + using (FileStream fileStreamPath = new FileStream(Path.GetFullPath(@"Data/Template.docx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) + { + //Open an existing Word document + using (WordDocument document = new WordDocument(fileStreamPath, FormatType.Automatic)) + { + string textToReplace = "Mexico"; + // Initialize text body part + TextBodyPart textBodyPart = new TextBodyPart(document); + // Initialize new paragraph + WParagraph paragraph = new WParagraph(document); + // Add the paragraph to the text body part + textBodyPart.BodyItems.Add(paragraph); + // Append a bookmark hyperlink to the paragraph + paragraph.AppendHyperlink("bookmark", "Mexico", HyperlinkType.Bookmark); + // Replace all occurrences of the target text with the text body part + document.Replace(textToReplace, textBodyPart, false, true); + // Clear the text body part + textBodyPart.Clear(); + // Create the output file stream + using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Result.docx"), FileMode.Create, FileAccess.ReadWrite)) + { + // Save the Word document to the output stream + document.Save(outputFileStream, FormatType.Docx); + } + } + } + } + } +} + diff --git a/Paragraphs/Replace-text-with-bookmark-hyperlink/.NET/Replace-text-with-bookmark-hyperlink/Replace-text-with-bookmark-hyperlink.csproj b/Paragraphs/Replace-text-with-bookmark-hyperlink/.NET/Replace-text-with-bookmark-hyperlink/Replace-text-with-bookmark-hyperlink.csproj new file mode 100644 index 00000000..6f153569 --- /dev/null +++ b/Paragraphs/Replace-text-with-bookmark-hyperlink/.NET/Replace-text-with-bookmark-hyperlink/Replace-text-with-bookmark-hyperlink.csproj @@ -0,0 +1,27 @@ + + + + Exe + net8.0 + Replace_text_with_bookmark_hyperlink + enable + enable + + + + + + + + + Always + + + Always + + + Always + + + +