I am trying to loop through layers in a map and return the name of the feature dataset. I will then be performing some task on features in a specific feature dataset. My map however is complex and includes some layers that do not reside in a feature dataset. My code errors at this point. I would like to somehow step over these layers without error. The line If pFeatureLayer.DataSourceType = "SDE Feature Class" is an attempt to limit my results since all of those layers reside in a feature dataset but that doesn't seem to be working. I am new to ArcObject so any help would be greatly appreciated!
Here is my code:
Dim pMapDocument As IMapDocument = New MapDocument()
If pMapDocument.IsMapDocument(destfile) Then
pMapDocument.Open(destfile, Nothing)
Dim pMap As IMap
Dim i As Integer
For i = 0 To pMapDocument.MapCount - 1 Step 1 + 1
pMap = pMapDocument.Map(i)
MsgBox(pMapDocument.DocumentFilename)
Dim pEnumLayer As IEnumLayer
Dim pID As New UID
Dim pFeatureClass As IFeatureClass
Dim pDataset As IDataset
Dim pFeatureLayer As IFeatureLayer2
pID.Value = "{6CA416B1-E160-11D2-9F4E-00C04F6BC78E}"
pEnumLayer = pMap.Layers(pID, True)
pEnumLayer.Reset()
pFeatureLayer = CType(pEnumLayer.Next, IFeatureLayer2)
Do Until pFeatureLayer Is Nothing
If pFeatureLayer.DataSourceType = "SDE Feature Class" Then
pFeatureClass = pFeatureLayer.FeatureClass
pDataset = pFeatureClass.FeatureDataset
MsgBox(pDataset.Name)
End If
pFeatureLayer = CType(pEnumLayer.Next, IFeatureLayer2)
Loop
Next i
End If
Next