How do I get the feature class name of layers that has lost there connections?

1765
2
Jump to solution
04-02-2012 10:11 AM
GenaroGarcia
New Contributor III
I???m in the need of get the feature class name of layers that lost their connections to SDE, broken data source.
They would contain a Red Explanation mark at the end of layer name located in the Table of Contents of ArcMap.

If you right-click on a layer and then select "Properties", the Layer Properties dialog is displayed.
Within the dialog there is a "Source" tab" that displays the Data Source information.
I need to retrieve the "Feature Class" information.

Any ideas, suggestions are appreciated...
0 Kudos
1 Solution

Accepted Solutions
by Anonymous User
Not applicable
Original User: jtkknelson

http://forums.arcgis.com/threads/50884-Programmatically-Identifying-Broken-Data-Links

Some old code below
Dim pEnumLayer As IEnumLayer, pdLayer As IDataLayer
layer = GetPath(pdLayer.DataSourceName)
            Valid = aLayer.Valid

Private Function GetPath(pDSName As IDatasetName) As String
    On Error Resume Next
    Dim DataType As String
    Dim genUtils As New clsGeneralUtilities
    GetPath = pDSName.WorkspaceName.PathName
    DataType = pDSName.Category
    If TypeOf pDSName Is IFeatureClassName Then
        Dim pFCName As IFeatureClassName
        Set pFCName = pDSName
        If Not pFCName.FeatureDatasetName Is Nothing Then
            GetPath = GetPath & "\" & pFCName.FeatureDatasetName.Name
        End If
    End If
    If pDSName.Name <> "point" And pDSName.Name <> "polygon" And pDSName.Name <> "arc" Then
       If Not DataType = "Shapefile Feature Class" Then
          GetPath = GetPath & "," & pDSName.Name
       Else
          GetPath = GetPath & "," & pDSName.Name & ".shp"
       End If
   Else
       GetPath = pDSName.WorkspaceName.PathName & "," & pFCName.FeatureDatasetName.Name
   End If
   
End Function

View solution in original post

0 Kudos
2 Replies
by Anonymous User
Not applicable
Original User: jtkknelson

http://forums.arcgis.com/threads/50884-Programmatically-Identifying-Broken-Data-Links

Some old code below
Dim pEnumLayer As IEnumLayer, pdLayer As IDataLayer
layer = GetPath(pdLayer.DataSourceName)
            Valid = aLayer.Valid

Private Function GetPath(pDSName As IDatasetName) As String
    On Error Resume Next
    Dim DataType As String
    Dim genUtils As New clsGeneralUtilities
    GetPath = pDSName.WorkspaceName.PathName
    DataType = pDSName.Category
    If TypeOf pDSName Is IFeatureClassName Then
        Dim pFCName As IFeatureClassName
        Set pFCName = pDSName
        If Not pFCName.FeatureDatasetName Is Nothing Then
            GetPath = GetPath & "\" & pFCName.FeatureDatasetName.Name
        End If
    End If
    If pDSName.Name <> "point" And pDSName.Name <> "polygon" And pDSName.Name <> "arc" Then
       If Not DataType = "Shapefile Feature Class" Then
          GetPath = GetPath & "," & pDSName.Name
       Else
          GetPath = GetPath & "," & pDSName.Name & ".shp"
       End If
   Else
       GetPath = pDSName.WorkspaceName.PathName & "," & pFCName.FeatureDatasetName.Name
   End If
   
End Function
0 Kudos
GenaroGarcia
New Contributor III
We came up with a easier solution that feeds our needs:


                //
                // --- create reference to ArcMap document
                //
                IDocument doc = arcMapDoc.Document;
                //
                // --- QI to IMXDocument
                //
                IMxDocument mxDoc = doc as IMxDocument;
                //
                // --- create reference to focus map
                //
                IMap map = mxDoc.ActiveView.FocusMap;
                //
                // --- create layers enumeration
                //
                IEnumLayer layerEnum = map.get_Layers(null, true);
                //
                // --- retrieve first layer
                //
                ILayer layer = layerEnum.Next() as ILayer;
                //
                // --- loop while layer is valid
                //
                while (layer != null)
                {
                    //
                    // --- QI to data layer
                    //
                    IDataLayer2 dataLayer = layer as IDataLayer2;
                    //
                    // --- test for valid data layer
                    //
                    if (dataLayer != null)
                    {
                        //
                        // --- QI to dataset name
                        //
                        IDatasetName2 datasetName = dataLayer.DataSourceName as IDatasetName2;

                        MessageBox.Show("DataSet Name: " + datasetName.Name.ToString());
                        //
                        // --- test for valid dataset name
                        //
                        if (datasetName != null)
                        {
0 Kudos