Independentsoft
Home
Products
Purchase
Support
Downloads
Company
Contact
Word .NET
>
Tutorial
> Add hyperlink
The following example shows you how to add a hyperlink.
See screenshot
.
C# example
using System; using Independentsoft.Office.Word; namespace Sample { class Program { static void Main(string[] args) { WordDocument doc = new WordDocument(); Run run = new Run(); run.AddText("Independentsoft"); run.Underline = new Underline(UnderlinePattern.Single); Independentsoft.Office.Word.Color runColor = new Independentsoft.Office.Word.Color(System.Drawing.Color.Blue); run.Color = new RunContentColor(runColor); Hyperlink link = new Hyperlink(); link.Add(run); link.Target = "http://www.independentsoft.com"; Paragraph paragraph = new Paragraph(); paragraph.Add(link); doc.Body.Add(paragraph); doc.Save("c:\\test.docx"); } } }
VB example
Imports System Imports Independentsoft.Office.Word Module Module1 Sub Main(ByVal args() As String) Dim doc As WordDocument = New WordDocument() Dim run As Run = New Run() run.AddText("Independentsoft") run.Underline = New Underline(UnderlinePattern.Single) Dim runColor As Independentsoft.Office.Word.Color = New Independentsoft.Office.Word.Color(System.Drawing.Color.Blue) run.Color = New RunContentColor(runColor) Dim link As Hyperlink = New Hyperlink() link.Add(run) link.Target = "http://www.independentsoft.com" Dim paragraph As Paragraph = New Paragraph() paragraph.Add(link) doc.Body.Add(paragraph) doc.Save("c:\test.docx") End Sub End Module