ArcObjects Library Reference

Get Path for a Layer Snippet

Get the full path and filename of a layer.

[C#]

///<summary>Get the full path and filename of a layer.</summary>
///  
///<param name="layer">An ILayer interface.</param>
///   
///<returns>A System.String that is the full path and filename for a layer</returns>
///   
///<remarks></remarks>
public System.String GetPathForALayer(ESRI.ArcGIS.Carto.ILayer layer)
{
  if(layer == null || !(layer is ESRI.ArcGIS.Geodatabase.IDataset))
  {
    return null;
  }
  ESRI.ArcGIS.Geodatabase.IDataset dataset = (ESRI.ArcGIS.Geodatabase.IDataset)(layer); // Explicit Cast

  return (dataset.Workspace.PathName + "\\" + dataset.Name);
}
[Visual Basic .NET]

'''<summary>Get the full path and filename of a layer.</summary>
'''  
'''<param name="layer">An ILayer interface.</param>
'''   
'''<returns>A System.String that is the full path and filename for a layer</returns>
'''   
'''<remarks></remarks>
Public Function GetPathForALayer(ByVal layer As ESRI.ArcGIS.Carto.ILayer) As System.String

  If layer Is Nothing OrElse Not (TypeOf layer Is ESRI.ArcGIS.Geodatabase.IDataset) Then
    Return Nothing
  End If

  Dim dataset As ESRI.ArcGIS.Geodatabase.IDataset = CType(layer, ESRI.ArcGIS.Geodatabase.IDataset) ' Explicit Cast

  Return (dataset.Workspace.PathName & "\" & dataset.Name)

End Function


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