This document is archived and information here might be outdated.  Recommended version.


Add Hyperlink Snippet (ArcObjects .NET 10.5 SDK)
ArcObjects Library Reference

Add Hyperlink Snippet

Adds a hyperlink to a selected feature in an IFeatureLayer.

[C#]
///<summary>Adds a hyperlink to a selected features in an IFeatureLayer.</summary>
///
///<param name="activeView">An IActiveView interface</param>
///<param name="strLink">A System.String that is the web site to link to. Example: "http://www.esri.com"</param>
///<param name="featurelayer">An IFeatureLayer interface to which to create the hyperlink for</param>
/// 
///<remarks>It is expected that you have features in the IFeatureLayer already selected before calling this routine.</remarks>
public void AddHyperlink(ESRI.ArcGIS.Carto.IActiveView activeView, System.String strLink, ESRI.ArcGIS.Carto.IFeatureLayer featureLayer)
{
  
  if(activeView == null || strLink == null || featureLayer == null)
  {
    return;
  }
  ESRI.ArcGIS.Carto.IMap map=activeView.FocusMap;
  ESRI.ArcGIS.Geodatabase.IEnumFeature enumFeature=map.FeatureSelection as ESRI.ArcGIS.Geodatabase.IEnumFeature; // Dynamic Cast
  enumFeature.Reset();

  ESRI.ArcGIS.Geodatabase.IFeature feature=enumFeature.Next();
  while (feature != null)
  {
    ESRI.ArcGIS.Carto.IHyperlink hyperlink=new ESRI.ArcGIS.Carto.HyperlinkClass();
    hyperlink.LinkType=ESRI.ArcGIS.Carto.esriHyperlinkType.esriHyperlinkTypeURL;
    hyperlink.Link=strLink;
    hyperlink.FeatureId=feature.OID;
    ESRI.ArcGIS.Carto.IHyperlinkContainer hyperlinkContainer=(ESRI.ArcGIS.Carto.IHyperlinkContainer)featureLayer; // Explicit Cast
    hyperlinkContainer.AddHyperlink(hyperlink);
    feature=enumFeature.Next();
  }
}
[Visual Basic .NET]
'''<summary>Adds a hyperlink to a selected features in an IFeatureLayer.</summary>
'''
'''<param name="activeView">An IActiveView interface</param>
'''<param name="strLink">A System.String that is the web site to link to. Example: "http://www.esri.com"</param>
'''<param name="featurelayer">An IFeatureLayer interface to which to create the hyperlink for</param>
''' 
'''<remarks>It is expected that you have features in the IFeatureLayer already selected before calling this routine.</remarks>
Public Sub AddHyperlink(ByVal activeView As ESRI.ArcGIS.Carto.IActiveView, ByVal strLink As System.String, ByVal featureLayer As ESRI.ArcGIS.Carto.IFeatureLayer)

  If activeView Is Nothing OrElse strLink Is Nothing OrElse featureLayer Is Nothing Then

    Return

  End If

  Dim map As ESRI.ArcGIS.Carto.IMap=activeView.FocusMap
  Dim enumFeature As ESRI.ArcGIS.Geodatabase.IEnumFeature=TryCast(map.FeatureSelection, ESRI.ArcGIS.Geodatabase.IEnumFeature) ' Dynamic Cast
  enumFeature.Reset()

  Dim feature As ESRI.ArcGIS.Geodatabase.IFeature=enumFeature.Next

  Do While Not feature Is Nothing

    Dim hyperlink As ESRI.ArcGIS.Carto.IHyperlink=New ESRI.ArcGIS.Carto.HyperlinkClass
    hyperlink.LinkType=ESRI.ArcGIS.Carto.esriHyperlinkType.esriHyperlinkTypeURL
    hyperlink.Link=strLink
    hyperlink.FeatureId=feature.OID
    Dim hyperlinkContainer As ESRI.ArcGIS.Carto.IHyperlinkContainer=CType(featureLayer, ESRI.ArcGIS.Carto.IHyperlinkContainer) ' Explicit Cast
    hyperlinkContainer.AddHyperlink(hyperlink)
    feature=enumFeature.Next

  Loop

End Sub

Additional Requirements
  • The code in this document requires the following References added to the Visual Studio project:
  • ESRI.ArcGIS.Carto
  • ESRI.ArcGIS.Geodatabase
  • ESRI.ArcGIS.System