GroupDocs.Assembly for .NET enables you to insert hyperlinks dynamically into documents using link tags. Hyperlinks can point to external URLs, bookmarks within the document, or specific cells/slides depending on the document type.
In your template (HyperlinkTemplate.docx), use link tags:
Please <<link [website.Url][website.Name]>> for more information.
After assembly:
Please Visit our website for more information.
(The text “Visit our website” will be a clickable hyperlink.)
Hyperlink with URL Only
If you omit the display text, the URL is used as the display text:
usingGroupDocs.Assembly;publicstaticvoidInsertHyperlinkUrlOnly(){varwebsite=newWebsite{Url="https://www.example.com"};DocumentAssemblerassembler=newDocumentAssembler();assembler.AssembleDocument("HyperlinkTemplate.docx","HyperlinkOutput.docx",newDataSourceInfo(website,"website"));Console.WriteLine("Hyperlink with URL only inserted successfully.");}
Template:
Visit <<link [website.Url]>> for more information.
Insert Multiple Hyperlinks from Collection
Insert hyperlinks for each item in a collection:
usingGroupDocs.Assembly;usingSystem.Collections.Generic;publicstaticvoidInsertHyperlinksFromCollection(){List<Website>websites=newList<Website>{newWebsite{Name="Home",Url="https://www.example.com"},newWebsite{Name="About",Url="https://www.example.com/about"},newWebsite{Name="Contact",Url="https://www.example.com/contact"}};DocumentAssemblerassembler=newDocumentAssembler();assembler.AssembleDocument("HyperlinksTemplate.docx","HyperlinksOutput.docx",newDataSourceInfo(websites,"websites"));Console.WriteLine("Hyperlinks inserted from collection successfully.");}
usingGroupDocs.Assembly;publicclassSection{publicstringTitle{get;set;}publicstringBookmarkName{get;set;}}publicstaticvoidInsertBookmarkLink(){varsection=newSection{Title="Go to Introduction",BookmarkName="Introduction"};DocumentAssemblerassembler=newDocumentAssembler();assembler.AssembleDocument("BookmarkLinkTemplate.docx","BookmarkLinkOutput.docx",newDataSourceInfo(section,"section"));Console.WriteLine("Bookmark hyperlink inserted successfully.");}
Template:
<<link [section.BookmarkName][section.Title]>>
Hyperlink to Cell (Spreadsheet Documents)
Link to cells in spreadsheet documents:
usingGroupDocs.Assembly;publicstaticvoidInsertCellLink(){vardata=new{CellReference="A1",DisplayText="Go to Home"};DocumentAssemblerassembler=newDocumentAssembler();assembler.AssembleDocument("CellLinkTemplate.xlsx","CellLinkOutput.xlsx",newDataSourceInfo(data,"data"));Console.WriteLine("Cell hyperlink inserted successfully.");}
Template:
<<link ["A1"]["Go to Home"]>>
Hyperlink to Slide (Presentation Documents)
Link to slides in presentation documents:
usingGroupDocs.Assembly;publicstaticvoidInsertSlideLink(){vardata=new{SlideNumber="Slide1",DisplayText="Go to First Slide"};DocumentAssemblerassembler=newDocumentAssembler();assembler.AssembleDocument("SlideLinkTemplate.pptx","SlideLinkOutput.pptx",newDataSourceInfo(data,"data"));Console.WriteLine("Slide hyperlink inserted successfully.");}
Template:
<<link ["Slide1"]["Go to First Slide"]>>
Using Uri Objects
You can use Uri objects directly:
usingGroupDocs.Assembly;usingSystem;publicclassWebsite{publicUriUrl{get;set;}publicstringName{get;set;}}publicstaticvoidInsertHyperlinkWithUri(){varwebsite=newWebsite{Url=newUri("https://www.example.com"),Name="Visit our website"};DocumentAssemblerassembler=newDocumentAssembler();assembler.AssembleDocument("HyperlinkTemplate.docx","HyperlinkOutput.docx",newDataSourceInfo(website,"website"));Console.WriteLine("Hyperlink with Uri object inserted successfully.");}
Warning
Link tags cannot be used within charts. For hyperlinks in charts, use alternative approaches or place links outside chart elements.
Advanced Usage Topics
To learn more about bookmark creation, complex hyperlink scenarios, and advanced link formatting, please refer to the advanced usage section.
More resources
GitHub Examples
You may easily run the code above and see the feature in action in our GitHub examples: