Class Hyperlink
Represents the Hyperlink.
Inheritance
Namespace: Syncfusion.DocIO.DLS
Assembly: Syncfusion.DocIO.Base.dll
Syntax
public class Hyperlink : Object
Examples
The following code example demonstrates how to insert a web link.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Create a new Word document
WordDocument document = new WordDocument();
//Add new section to the document
IWSection section = document.AddSection();
//Add new paragraph to the section
IWParagraph paragraph = section.AddParagraph();
paragraph.AppendText("Web Hyperlink: ");
paragraph = section.AddParagraph();
//Append web hyperlink to the paragraph
IWField field = paragraph.AppendHyperlink("http://www.syncfusion.com", "Syncfusion", HyperlinkType.WebLink);
//Save the Word document
document.Save("Sample.docx", FormatType.Docx);
//Close the document
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
'Create a new Word document
Dim document As New WordDocument()
'Add new section to the document
Dim section As IWSection = document.AddSection()
'Add new paragraph to the section
Dim paragraph As IWParagraph = section.AddParagraph()
paragraph.AppendText("Web Hyperlink: ")
paragraph = section.AddParagraph()
'Append web hyperlink to the paragraph
Dim field As IWField = paragraph.AppendHyperlink("http://www.syncfusion.com", "Syncfusion", HyperlinkType.WebLink)
'Save the Word document
document.Save("Sample.docx", FormatType.Docx)
'Close the document
document.Close()
End Sub
The following code example demonstrates how to add an email link.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Create a new Word document
WordDocument document = new WordDocument();
//Add new section to the document
IWSection section = document.AddSection();
//Add new paragraph to the section
IWParagraph paragraph = section.AddParagraph();
paragraph.AppendText("Email hyperlink: ");
paragraph = section.AddParagraph();
//Append Email hyperlink to the paragraph
paragraph.AppendHyperlink("mailto:john@gmail.com","John" , HyperlinkType.EMailLink);
//Save the Word document
document.Save("Sample.docx", FormatType.Docx);
//Close the document
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
'Create a new Word document
Dim document As New WordDocument()
'Add new section to the document
Dim section As IWSection = document.AddSection()
'Add new paragraph to the section
Dim paragraph As IWParagraph = section.AddParagraph()
paragraph.AppendText("Email hyperlink: ")
paragraph = section.AddParagraph()
'Append Email hyperlink to the paragraph
paragraph.AppendHyperlink("mailto:john@gmail.com", "John", HyperlinkType.EMailLink)
'Save the Word document
document.Save("Sample.docx", FormatType.Docx)
'Close the document
document.Close()
End Sub
The following code example demonstrates how to add a file hyperlink.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Create a new Word document
WordDocument document = new WordDocument();
//Add new section to the document
IWSection section = document.AddSection();
//Add new paragraph to the section
IWParagraph paragraph = section.AddParagraph();
paragraph.AppendText("File Hyperlinks: ");
paragraph = section.AddParagraph();
//Append hyperlink field to the paragraph
paragraph.AppendHyperlink(@"D:\Template.docx","File", HyperlinkType.FileLink);
//Save the Word document
document.Save("Sample.docx", FormatType.Docx);
//Close the document
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
'Create a new Word document
Dim document As New WordDocument()
'Add new section to the document
Dim section As IWSection = document.AddSection()
'Add new paragraph to the section
Dim paragraph As IWParagraph = section.AddParagraph()
paragraph.AppendText("File Hyperlinks: ")
paragraph = section.AddParagraph()
'Append hyperlink field to the paragraph
paragraph.AppendHyperlink("D:\Template.docx", "File", HyperlinkType.FileLink)
'Save the Word document
document.Save("Sample.docx", FormatType.Docx)
'Close the document
document.Close()
End Sub
The following code example demonstrates how to add a bookmark hyperlink.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Create a new Word document
WordDocument document = new WordDocument();
//Add new section to the document
IWSection section = document.AddSection();
//Add new paragraph to the section
IWParagraph paragraph = section.AddParagraph();
//Create new Bookmark
paragraph.AppendBookmarkStart("Introduction");
paragraph.AppendText("Hyperlink");
paragraph.AppendBookmarkEnd("Introduction");
paragraph.AppendText("\nA hyperlink is a reference or navigation element in a document to another section of the same document or to another document that may be on or part of a (different) domain.");
paragraph = section.AddParagraph();
paragraph.AppendText("Bookmark Hyperlink: ");
paragraph = section.AddParagraph();
//Append Bookmark hyperlink to the paragraph
paragraph.AppendHyperlink("Introduction", "Bookmark", HyperlinkType.Bookmark);
//Save the Word document
document.Save("Sample.docx", FormatType.Docx);
//Close the document
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
'Create a new Word document
Dim document As New WordDocument()
'Add new section to the document
Dim section As IWSection = document.AddSection()
'Add new paragraph to the section
Dim paragraph As IWParagraph = section.AddParagraph()
'Create new Bookmark
paragraph.AppendBookmarkStart("Introduction")
paragraph.AppendText("Hyperlink")
paragraph.AppendBookmarkEnd("Introduction")
paragraph.AppendText(vbLf & "A hyperlink is a reference or navigation element in a document to another section of the same document or to another document that may be on or part of a (different) domain.")
paragraph = section.AddParagraph()
paragraph.AppendText("Bookmark Hyperlink: ")
paragraph = section.AddParagraph()
'Append Bookmark hyperlink to the paragraph
paragraph.AppendHyperlink("Introduction", "Bookmark", HyperlinkType.Bookmark)
'Save the Word document
document.Save("Sample.docx", FormatType.Docx)
'Close the document
document.Close()
End Sub
The following code example demonstrates how to add image hyperlink.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Create a new Word document
WordDocument document = new WordDocument();
//Add new section to the document
IWSection section = document.AddSection();
//Add new paragraph to the section
IWParagraph paragraph = section.AddParagraph();
paragraph.AppendText("Image Hyperlink");
paragraph = section.AddParagraph();
//Create a new image instance and load image
WPicture picture = new WPicture(document);
picture.LoadImage(Image.FromFile("Image.png"));
//Append new image hyperlink to the paragraph
paragraph.AppendHyperlink("http://www.syncfusion.com", picture, HyperlinkType.WebLink);
//Save the Word document
document.Save("Sample.docx", FormatType.Docx);
//Close the document
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
'Create a new Word document
Dim document As New WordDocument()
'Add new section to the document
Dim section As IWSection = document.AddSection()
'Add new paragraph to the section
Dim paragraph As IWParagraph = section.AddParagraph()
paragraph.AppendText("Image Hyperlink")
paragraph = section.AddParagraph()
'Create a new image instance and load image
Dim picture As New WPicture(document)
picture.LoadImage(Image.FromFile("Image.png"))
'Append new image hyperlink to the paragraph
paragraph.AppendHyperlink("http://www.syncfusion.com", picture, HyperlinkType.WebLink)
'Save the Word document
document.Save("Sample.docx", FormatType.Docx)
'Close the document
document.Close()
End Sub
Constructors
Hyperlink(WField)
Initializes a new instance of the Hyperlink class.
Declaration
public Hyperlink(WField hyperlink)
Parameters
Type | Name | Description |
---|---|---|
WField | hyperlink | The hyperlink. |
Properties
BookmarkName
Gets or sets the bookmark name for Bookmark hyperlink.
Declaration
public string BookmarkName { get; set; }
Property Value
Type |
---|
System.String |
FilePath
Gets or sets the file path for file link.
Declaration
public string FilePath { get; set; }
Property Value
Type | Description |
---|---|
System.String | The string that specifies the path of the file. |
LocalReference
Gets or sets the Local Reference for the hyperlink
Declaration
public string LocalReference { get; set; }
Property Value
Type | Description |
---|---|
System.String | The string that specifies the local reference. |
PictureToDisplay
Gets or sets the image which will be displayed on the place of hyperlink.
Declaration
public WPicture PictureToDisplay { get; set; }
Property Value
Type | Description |
---|---|
WPicture | The WPicture to display. |
TextToDisplay
Gets or sets the text which will be displayed on the place of hyperlink.
Declaration
public string TextToDisplay { get; set; }
Property Value
Type | Description |
---|---|
System.String | The string that specifies the text to display. |
Type
Gets or sets the hyperlink type.
Declaration
public HyperlinkType Type { get; set; }
Property Value
Type |
---|
HyperlinkType |
Uri
Gets or sets URL link for web link.
Declaration
public string Uri { get; set; }
Property Value
Type | Description |
---|---|
System.String | The string that specifies URL. |