Click here to Skip to main content
15,886,026 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I use this article C#: Create and Manipulate Word Documents Programmatically Using DocX[^], but i cannot understand how add hyperlinks to doc.

C#
string fileName = @"DocXExample.docx";

            // Create a document in memory:
            var doc = DocX.Create(fileName);

            // Insert a paragrpah:
            doc.InsertParagraph("This is my first paragraph");
          
            doc.AddHyperlink("URL", new Uri("http://www.google.com")); // this code not work
          
            doc.Save();

            // Open in Word:
            Process.Start("WINWORD.EXE", fileName);
Posted
Updated 14-Sep-14 21:13pm
v2
Comments
Pheonyx 15-Sep-14 4:22am    
You say "this code not work", what do you mean by this? Does it throw an error? Does it just produce no text at all?

1 solution

The reason it is not working is that although you are adding it to the document you aren't putting it on the page.

DocX Help[^] < This link takes you to a blog explaining how to put a hyperlink into a DocX document. It took a short amount of googling (all of about 2 minutes) which is something you should have done yourself in the first place.

Good luck.
 
Share this answer
 

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