How to list data (ArcObjects .NET 10.6 SDK)
ArcObjects Help for .NET developers > Developing with ArcGIS > Learning ArcObjects > Using geoprocessing > Working with multiple datasets > How to list data (ArcObjects .NET 10.6 SDK)

How to list data


Listing data

One of the foremost tasks in a batch processing program is cataloging the available data so it can iterate through the data during processing. The geoprocessor has a number of methods built specifically for creating such lists. These methods work with all types of data and provide flexibility for restricting a search by name or data category. 
The following table lists these methods and their syntax:
Method
Description
ListDatasets (string Wild Card, string Dataset Type)
Returns an enumeration of datasets in the current workspace based on a query string and type
ListFeatureClasses (string Wild Card, string Feature Type, string Dataset)
Returns an enumeration of feature classes in the current workspace or optional dataset based on a query string and type
ListRasters (string Wild Card, string Raster Type)
Returns an enumeration of rasters in the current workspace based on a query string and type
ListTables (string Wild Card, string Table Type)
Returns an enumeration of tables in the current workspace based on a query string and type
ListWorkspaces (string Wild Card, string WorkspaceType)
Returns an enumeration of workspaces in the current workspace based on a query string and type
The methods listed in the table require the workspace environment to be specified previously to identify the location from which the enumeration will be created. A workspace can be a directory, database, or dataset containing geographic data (for example, geodatabase, geodatabase feature dataset, or coverage, folder) and other supporting data. The wild card option uses an asterisk to mean any character. More than one asterisk can be used in the wild card string. For example, the wild card *road* can be used to find items that have the word road in their names.
The return value of each of these methods is IGpEnumList. Once the enumeration has been created with the values you want, you can loop through it in your program to work with each individual value.
All methods have a wild card parameter, which is used to restrict the objects or datasets listed by name. A wild card defines a name filter, and all the contents in the newly created enumeration must pass that filter. For example, you may want to list all the feature classes in a workspace that start with the letter d. The following code example shows how to do this:
[C#]
public void ExampleGPListFeatureClasses(Geoprocessor GP)
{

    // List all feature classes in the workspace starting with d.
    GP.SetEnvironmentValue("workspace", @"C:\Uc2003\Portland_OR.gdb");
    IGpEnumList fcs=GP.ListFeatureClasses("d*", "", "");
    string fc=fcs.Next();

    while (fc != "")
    {

        Console.WriteLine(fc);
        fc=fcs.Next();

    }

}
[VB.NET]
Public Sub ExampleGPListFeatureClasses(ByVal GP As Geoprocessor)
    
    ' List all feature classes in the workspace starting with d.
    GP.SetEnvironmentValue("workspace", "C:\Uc2003\Portland_OR.gdb")
    Dim fcs As ESRI.ArcGIS.Geoprocessing.IGpEnumList=GP.ListFeatureClasses("d*", "", "")
    Dim fc As String=fcs.Next()
    
    Do While fc <> ""
        
        Console.WriteLine(fc)
        fc=fcs.Next()
        
    Loop
    
End Sub
The enumeration can also be restricted to match certain data properties, such as only polygon feature classes, integer fields, or coverage datasets. This is what the Type parameter is used for in all the methods. In the following code example, the feature classes in a workspace are filtered using a wild card and a data type, so only polygon feature classes that start with the letter d are in the resulting enumeration:
[C#]
public void ExampleGPListFeatureClassesPolygon(Geoprocessor GP)
{

    // List all feature classes in the workspace that start with d and are of type polygon.
    GP.SetEnvironmentValue("workspace", @"C:\Uc2003\Portland_OR.gdb");
    IGpEnumList fcs=GP.ListFeatureClasses("d*", "polygon", "");
    string fc=fcs.Next();

    while (fc != "")
    {

        Console.WriteLine(fc);
        fc=fcs.Next();

    }

}
[VB.NET]
Public Sub ExampleGPListFeatureClassesPolygon(ByVal GP As Geoprocessor)
    
    ' List all feature classes in the workspace that start with d and are of type polygon.
    GP.SetEnvironmentValue("workspace", "C:\Uc2003\Portland_OR.gdb")
    Dim fcs As ESRI.ArcGIS.Geoprocessing.IGpEnumList=GP.ListFeatureClasses("d*", "polygon", "")
    Dim fc As String=fcs.Next()
    
    Do While fc <> ""
        
        Console.WriteLine(fc)
        fc=fcs.Next()
        
    Loop
    
End Sub
The following code example shows how to use an IGpEnumList created by a list function. The script is used to create raster pyramids for all the rasters that are tagged image file format (TIFF) images in a folder.
[C#]
public void ExampleGPListRasters(Geoprocessor GP)
{

    // List all TIFF files in the workspace and build pyramids.
    GP.SetEnvironmentValue("workspace", @"C:\Corey\Ccm\results");
    IGpEnumList rasters=GP.ListRasters("*", "TIFF");
    string raster=rasters.Next();

    // Intialize the BuildPyramids tool.
    BuildPyramids pyramids=new BuildPyramids();

    while (raster != "")
    {

        // Set input raster dataset.
        pyramids.in_raster_dataset=raster;
        GP.Execute(pyramids, null);
        raster=rasters.Next();
    }

}
[VB.NET]
Public Sub ExampleGPListRasters(ByVal GP As Geoprocessor)
    
    ' List all TIFF files in the workspace and build pyramids.
    GP.SetEnvironmentValue("workspace", "C:\Corey\Ccm\results")
    Dim rasters As ESRI.ArcGIS.Geoprocessing.IGpEnumList=GP.ListRasters("*", "TIFF")
    Dim raster As String=rasters.Next()
    
    ' Intialize the BuildPyramids tool.
    Dim pyramids As BuildPyramids=New BuildPyramids()
    
    Do While raster <> ""
        
        ' Set input raster dataset.
        pyramids.in_raster_dataset=raster
        GP.Execute(pyramids, Nothing)
        raster=rasters.Next()
        
    Loop
    
End Sub
The default behavior for all list methods is to list all supported types. A keyword is used to restrict the returned enumeration to a specific type. The type keywords for each method are listed in the following table:
Method
Type Keywords
ListDatasets
All, Feature, Coverage, RasterCatalog, CAD, VPF, TIN, Topology
ListFeatureClasses
All, Point, Label, Node, Line, Arc, Route, Polygon, Region
ListFields
All, SmallInteger, Integer, Single, Double, String, Date, OID, Geometry, BLOB
ListWorkspaces
All, Coverage, Access, SDE, Folder
ListTables
All, dBASE, INFO
ListRasters
All, ADRG, BIL, BIP, BSQ, BMP, CADRG, CIB, ERS, GIF, GIS, GRID, STACK, IMG, JPG, JP2, LAN, SID, SDE, TIF, RAW, PNG, NTF, DDF, RST, HDF
A common conversion task is the large-scale transfer of data from one format to another. See the sample program that takes advantage of ListWorkspaces, ListFeatureClasses, ListTables, and ListDatasets to identify all personal geodatabases in a folder and converts the contents of each to file geodatabases.


See Also:

Samples:




To use the code in this topic, reference the following assemblies in your Visual Studio project. In the code files, you will need using (C#) or Imports (VB .NET) directives for the corresponding namespaces (given in parenthesis below if different from the assembly name):