amgarci145

Hyperlink snippet example

Discussion created by amgarci145 on Nov 22, 2011
Latest reply on Nov 25, 2011 by amgarci145
Hi,

I am new to working with ArcObjects specifically using vb.net code.

I have placed a command button on a form.  When one clicks the button it should open the URL.
I have placed the VB.Net AddHyperlink snippet example, but I am not sure how to call the code with the button click event?  In addition, not sure where to place the URL? I know it???s a strLink, but how do you call it.

For example on Form1 I have this hyperlink snippet code:

'<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 Or Else 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)' Eplicit Cast
    hyperlinkContainer.AddHyperlink(hyperlink)
    feature = enumFeature.Next
  Loop

End Sub

These references were added
  ESRI.ArcGIS.Carto
  ESRI.ArcGIS.Geodatabase
  ESRI.ArcGIS.System


In the button click event I  try to call the hyperlink
call AddHyperlink()

of course nothing happens.

Can someone help me get this code working,so I can see how the hyperlink snippet code works for vb.net

Thank You

Angie

Outcomes