1. How to Use C#/VB.NET Add Hyperlink in Word
Why Add Hyperlink in Word?
Hyperlink is an element in an electronic document that links to another place in the same
document or to an entirely different document. Typically, you click on the hyperlink to follow the
link. Hyperlinks are the most essential ingredient of all hypertext systems, including the World
Wide Web. And Microsoft Word is the most popular program for us to design and edit content.
Add hyperlink in Word can easily link to other place by simply press “Ctrl” and right click.
In Microsoft Word, it’s easy to add hyperlink. Select the text or picture that you want to display as
the hyperlink. On the Insert tab, in the Links group, click Hyperlink. To link to an existing file or
Web page, click Existing File or Web Page under Link to, and then type the address that you want
to link to in the Address box. If you don't know the address for a file, click the arrow in the Look
in list, and then navigate to the file that you want.
On the other hand, by using C#/VB.NET, you also can add hyperlink in Word and you are not
necessary to install Microsoft Office in your system.
How to Use C# Add Hyperlink in Word
Spire.Doc is a Word Component which enables user to perform a wide range of Word document
processing tasks directly for .NET and Silverlight which presents a simply way to use Word
hyperlink, including add hyperlink in Word.
Download Spire.Doc (or Spire.Office which includes Spire.Doc) with .NET framework together.
Suppose we have written a word document which we want to add hyperlinks. We can use
paragraph.AppendHyperlink method to insert hyperlinks. In paragraph.AppendHyperlink method
we give it three parameters. The first one is the text of the hyperlink, the second is the address of
the hyperlink and the last is the format of the hyperlink.
C# add hyperlinks in word:
01 using Spire.Doc;
02 using Spire.Doc.Documents;
03
04 namespace Hyperlink
05 {
06 class Program
07 {
08 static void Main(string[] args)
09 {
10 //Create word document
3. How to Use VB.NET Add Hyperlink in Word
01 Imports Spire.Doc
02 Imports Spire.Doc.Documents
03
04 Module Module1
05
06 Sub Main()
07 'Create word document
08 Dim document As New Document()
09
10 'Create section
11 Dim section As Section = document.AddSection()
12
13 'Add paragraph
14 Dim paragraph As Paragraph = section.AddParagraph()
15
16 'Append text
17 paragraph.AppendText("Spire.XLS for .NET " & vbCrLf & " e-iceblue company Ltd.
2002-2010 All rights reserverd")
18 paragraph.ApplyStyle(BuiltinStyle.Heading2)
19 paragraph = section.AddParagraph()
20 paragraph.AppendText("Home page")
21 paragraph.ApplyStyle(BuiltinStyle.Heading2)
22
23 'Add paragraph
24 paragraph = section.AddParagraph()
25
26 'Insert a weblink
27 paragraph.AppendHyperlink("www.e-iceblue.com", "www.e-iceblue.com",
HyperlinkType.WebLink)
28
29 'Add paragraph
30 paragraph = section.AddParagraph()
31
32 'Append text
33 paragraph.AppendText("Contact US")
34 paragraph.ApplyStyle(BuiltinStyle.Heading2)
35
36 'Add paragraph
37 paragraph = section.AddParagraph()
38
39 'Insert an Emaillink
40 paragraph.AppendHyperlink("mailto:support@e-iceblue.com", "support@e-
4. iceblue.com", HyperlinkType.EMailLink)
41
42 'Save the file.
43 document.SaveToFile("Sample.doc")
44
45 'Launch the file.
46 System.Diagnostics.Process.Start("Sample.doc")
47 End Sub
48 End Module
Screenshot after running the code above:
More about Spire.Doc
Download Spire.Doc
Purchase Spire.Doc