ArcObjects Library Reference  (Carto)    

IDataLayer Example

[Visual Basic 6.0]
Private Sub IDataLayerExample()
    ' prints out path, feature dataset, and feature class/dataset name
    Dim pMxdoc As IMxDocument
    Dim pApp As IApplication
    Set pApp = Application
    Set pMxdoc = pApp.Document
    Dim pLayer As ILayer
    Dim pDataLayer As IDataLayer
    Dim pDatasetName As IDatasetName
    Dim pWSName As IWorkspaceName
    Dim sFDS As String
    Dim pFCName As IFeatureClassName
    Dim i As Integer
    For i = 0 To pMxdoc.FocusMap.LayerCount - 1
        Set pLayer = pMxdoc.FocusMap.Layer(i)
        If TypeOf pLayer Is IDataLayer Then
            sFDS = ""
            Set pDataLayer = pMxdoc.FocusMap.Layer(i)
            Set pDatasetName = pDataLayer.DataSourceName
            Set pWSName = pDatasetName.WorkspaceName
            If TypeOf pDatasetName Is IFeatureClassName Then
                Set pFCName = pDatasetName
                If Not pFCName.FeatureDatasetName Is Nothing Then
                    sFDS = pFCName.FeatureDatasetName.Name
                End If
            End If    ' output results to the VB or VBA Immediate window
            Debug.Print "(" + Format(i) + ") Path: " + pWSName.PathName
            Debug.Print "Feature Dataset: " + sFDS
            Debug.Print "Feature Class/Dataset: " + pDatasetName.Name
        End If
    Next i
End Sub

[Visual Basic .NET, C#, C++]
No example is available for Visual Basic .NET, C#, or C++. To view a Visual Basic 6.0 example, click the Language Filter button Language Filter in the upper-left corner of the page.