Friday, 07 January 2011 07:10

Insert Hyperlink to Word in C#, VB.NET

Written by  Administrator
Rate this item
(0 votes)

Word Hyperlink can be inserted automatically when users press ENTER or SPACEBAR after typing address of an existing Web page, such as Also, users can insert customized hyperlink in Word for text to picture that they want to display as hyperlink. The hyperlink for text or picture can be Web page, E-mail address, other files or document.

Spire.Doc for .NET, a professional .NET Word component to manipulate Word documents, enables users to insert hyperlink in Word with C#/VB.NET. You can invoke the method paragraph.AppendHyperlink(string link, string text, HyperlinkType) to insert hyperlink in Word directly via Spire.Doc for .NET. And the HyperlinkType in method can be set as WebLink, EmailLink etc. Below is an effective screenshot after inserting hyperlink to Word in C#, VB.NET

Insert Word Hyperlink

Download and install Spire.Doc for .NET and then use the following code to insert hyperlink in Word.

using Spire.Doc;
using Spire.Doc.Documents;
using System.Drawing;
namespace InsertHyperlink
    class Program
        static void Main(string[] args)
            //Create Word
            Document document = new Document();
            Section section = document.AddSection();
            Paragraph paragraph = section.AddParagraph();

            //Set Paragraph Styles
            ParagraphStyle txtStyle = new ParagraphStyle(document);
            txtStyle.Name = "Style";
            txtStyle.CharacterFormat.FontName = "Impact";
            txtStyle.CharacterFormat.FontSize = 16;
            txtStyle.CharacterFormat.TextColor = Color.RosyBrown;

            ParagraphStyle hyperlinkstyle = new ParagraphStyle(document);
            hyperlinkstyle.Name = "linkStyle";
            hyperlinkstyle.CharacterFormat.FontName = "Calibri";
            hyperlinkstyle.CharacterFormat.FontSize = 15;

            //Append Text and Set Text Format
            paragraph = section.AddParagraph();
            paragraph.AppendText("Home page");

            //Insert Hyperlink(Web Page)
            paragraph = section.AddParagraph();
            paragraph.AppendHyperlink("", "", HyperlinkType.WebLink);

            //Append text
            paragraph = section.AddParagraph();
            paragraph.AppendText("Contact US");

            //Insert Hyperlink(E-mail Address);
            paragraph = section.AddParagraph();
            paragraph.AppendHyperlink("", "", HyperlinkType.EMailLink);

            //Save and Launch
            document.SaveToFile("Hyperlink.docx", FileFormat.Docx);

Imports Spire.Doc
Imports Spire.Doc.Documents
Imports System.Drawing
Namespace InsertHyperlink
	Class Program
		Private Shared Sub Main(args As String())
			'Create Word
			Dim document As New Document()
			Dim section As Section = document.AddSection()
			Dim paragraph As Paragraph = section.AddParagraph()

			'Set Paragraph Styles
			Dim txtStyle As New ParagraphStyle(document)
			txtStyle.Name = "Style"
			txtStyle.CharacterFormat.FontName = "Impact"
			txtStyle.CharacterFormat.FontSize = 16
			txtStyle.CharacterFormat.TextColor = Color.RosyBrown

			Dim hyperlinkstyle As New ParagraphStyle(document)
			hyperlinkstyle.Name = "linkStyle"
			hyperlinkstyle.CharacterFormat.FontName = "Calibri"
			hyperlinkstyle.CharacterFormat.FontSize = 15

			'Append Text and Set Text Format
			paragraph = section.AddParagraph()
			paragraph.AppendText("Home page")

			'Insert Hyperlink(Web Page)
			paragraph = section.AddParagraph()
			paragraph.AppendHyperlink("", "", HyperlinkType.WebLink)

			'Append text
			paragraph = section.AddParagraph()
			paragraph.AppendText("Contact US")

			'Insert Hyperlink(E-mail Address);
			paragraph = section.AddParagraph()
			paragraph.AppendHyperlink("", "", HyperlinkType.EMailLink)

			'Save and Launch
			document.SaveToFile("Hyperlink.docx", FileFormat.Docx)

		End Sub
	End Class
End Namespace

Spire.Doc is a Microsoft Word component, which enables users to perform a wide range of Word document processing tasks directly, such as generate, read, write and modify Word document in WPF, .NET and Silverlight.

Additional Info

  • tutorial_title: Insert Hyperlink to Word Document
Last modified on Thursday, 05 November 2020 02:08