How to Insert Hyperlink in Word Document with C#/VB.NET

MS Word provides users with function to insert hyperlink. Hyperlink can lead readers to click it to learn more information which is related to contents. It can be website address, other Word document or Email address.

Generally speaking, we can insert hyperlink directly in document or for some special words, such as a famous person’s name, company name and so on. In this post, I will show how to insert hyperlink in Word by using C#/VB.NET.

In my example, I will show two hyperlinks in document, which is inserted directly. Type of two hyperlinks are website url.

Detailed Step Shown as Following:

  1. Create a new document and add section in it.
  2. Add paragraph in section and append text as title.
  3. Define a style, including font style, size and text color.
  4. Insert hyperlink. Firstly, append text as cue words. Secondly, apply style in cue word paragraph. Thirdly, append hyperlink in new paragraph. There are three parameters passed to AppendHyperlink method, link, link text and link type. Fourthly, apply style for hyperlink.
  5. Save and launch file.

Main Coding:


using System;

using System.Drawing;

using Spire.Doc;

using Spire.Doc.Documents;

namespace Wordlink


    class Link


        static void Main(string[] args)


            //Create Document

            Document document = new Document();

            //Add Section and Paragraph

            Section section = document.AddSection();

            Paragraph paragraph = section.AddParagraph();

            //Add Text

            paragraph.AppendText(“Word Hyperlink”);



            ParagraphStyle style = new ParagraphStyle(document);

            style.Name = “Link Style”;

            style.CharacterFormat.FontName = “Calibri”;

            style.CharacterFormat.FontSize = 14;

            style.CharacterFormat.TextColor = Color.DarkOliveGreen;


            //Insert Link

            paragraph = section.AddParagraph();

            paragraph.AppendText(“Visit WordPress Blog:”);


            paragraph = section.AddParagraph();

            paragraph.AppendHyperlink(“”, “”, HyperlinkType.WebLink);


            paragraph = section.AddParagraph();

            paragraph.AppendText(“Help Center:”);


            paragraph = section.AddParagraph();

            paragraph.AppendHyperlink(“”, “”, HyperlinkType.WebLink);



            document.SaveToFile(“Link.docx”, FileFormat.Docx);







Imports System

Imports System.Drawing

Imports Spire.Doc

Imports Spire.Doc.Documents

Namespace Wordlink

    Friend Class Link

        Shared Sub Main(ByVal args() As String)

            ‘Create Document

            Dim document As New Document()

            ‘Add Section and Paragraph

            Dim section As Section = document.AddSection()

            Dim paragraph As Paragraph = section.AddParagraph()

            ‘Add Text

            paragraph.AppendText(“Word Hyperlink”)



            Dim style As New ParagraphStyle(document)

            style.Name = “Link Style”

            style.CharacterFormat.FontName = “Calibri”

            style.CharacterFormat.FontSize = 14

            style.CharacterFormat.TextColor = Color.DarkOliveGreen


            ‘Insert Link

            paragraph = section.AddParagraph()

            paragraph.AppendText(“Visit WordPress Blog:”)


            paragraph = section.AddParagraph()

            paragraph.AppendHyperlink(“”, “”, HyperlinkType.WebLink)


            paragraph = section.AddParagraph()

            paragraph.AppendText(“Help Center:”)


            paragraph = section.AddParagraph()

            paragraph.AppendHyperlink(“”, “”, HyperlinkType.WebLink)



            document.SaveToFile(“Link.docx”, FileFormat.Docx)



        End Sub

    End Class

End Namespace

Result Shown as Following:


Click Here to Learn more about Spire.Doc

Click Here to Download Spire.Doc

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s