Listing 1: Execute the Buffer tool 

using ESRI.ArcGIS.Geoprocessor;
using ESRI.ArcGIS.AnalysisTools;

// Initialize the Geoprocessor 
GeoProcessor GP = new Geoprocessor();

// Set workspace environment
GP.SetEnvironmentValue("workspace", @ "C:\Data\Nfld.gdb");

// Initialize the Buffer Tool
Buffer bufferTool = new Buffer();
bufferTool.in_features = "roads";
bufferTool.out_feature_class = "roads_500";
bufferTool.buffer_Distance_or_field = "500 METERS";

// Execute the buffer
GP.Execute(bufferTool, null)

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Listing 2: Execute a model tool by name.

using ESRI.ArcGIS.Geoprocessor;
using ESRI.ArcGIS.esriSystem;

public void SampleCalculateBestPathTool()
{

  // Initialize the geoprocessor.
  Geoprocessor GP = new Geoprocessor();

  // Add the BestPath toolbox.
  GP.AddToolbox(@"C:\SanDiego\BestPath.tbx");

  // Generate the array of parameters.
  IVariantArray parameters = new VarArrayClass();
  parameters.Add(@"C:\SanDiego\source.shp");
  parameters.Add(@"C:\SanDiego\destination.shp");
  parameters.Add(@"C:\SanDiego\bestpath.shp");

  // Execute the model tool by name.
  GP.Execute("CalculateBestPath", parameters, null);

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++

List 3: Return the ArcCatalog path to the output feature class.

using ESRI.ArcGIS.Geoprocessing;
using ESRI.ArcGIS.Geoprocessor;
using ESRI.ArcGIS.Geoprocessing;
using ESRI.ArcGIS.AnalysisTools;

// TODO: Initialize Buffer and provide parameter values.

// The return value is an Object of type string
IGeoProcessorResult pResult = (IGeoProcessorResult) GP.Execute(bufferTool, null); 
object path = pResult.ReturnValue;

IFeatureClass pFC = GP.Open(path);

List 4: Return the default Grid Size.

using ESRI.ArcGIS.Geoprocessing;
using ESRI.ArcGIS.Geoprocessor;
using ESRI.ArcGIS.Geoprocessing;
using ESRI.ArcGIS.DataManagementTools;

// TODO: Initialize Calculate Grid Index and provide parameter values.

// The return value is an Object of type double. 
IGeoProcessorResult pResult = GP.Execute(calculateGridIndexTool, null); 
object defgrid = pResult.ReturnValue;

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Listing 5: Get all tool messages by serverity. 

IGeoProcessorResult  result = (IGeoProcessorResult ) GP.Execute(bufferTool, null);

object infoMsgs = 0;
object errorMgs = 2;

if (result == null)
{
   // Informative messages
   Console.WriteLine(GP.GetMessages(ref errorMgs));
}
else
{
   // Error messages
   Console.WriteLine(result.GetMessages(ref infoMsgs));
}

Listing 6: Get individual messages.

// Execute Union
IGeoProcessorResult result = GP.Execute(uniontool, null); 

if (result. != null) { 
   for (int Count = 0; Count <= result.MessageCount - 1; Count++) 
   { 
      Console.WriteLine(result.GetMessage(Count)); 
   }
} 

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Listing 7: Iterate through a list of TIFF files and Build Pyramids

// List all TIFF files in the workspace and build pyramids 
GP.SetEnvironmentValue("workspace", @"C:\Ccm\Data"); 

IGpEnumList rasters = GP.ListRasters("*", "TIFF"); 
string raster = rasters.Next(); 

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

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

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Listing 8: Describe a feature class to obtain the properties.

// Describe the input feature class.
object dtype = "";
IDataElement dataelement = GP.GetDataElement(@"C:\GP\PortlandOR.gdb\streets", ref dtype);
        
// Open the feature class data element and get the shape type.
IDEFeatureClass defc = dataelement as IDEFeatureClass;            
if (defc.ShapeType == esriGeometryType.esriGeometryPolyline)
 Console.WriteLine("ShapeType is polyline.");

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Listing 9: Add a field to a table.

using ESRI.ArcGIS.Geoprocessor;
using ESRI.ArcGIS.DataManagementTools;

// Adding a Field - Geoprocessing
Geoprocessor GP = new Geoprocessor();
AddField addfieldtool = new AddField(@"C:\nfld.gdb\wells", "Depth", "DOUBLE");

// Execute tool
IGeoProcessorResult result = (IGeoProcessorResult ) GP.Execute(addfieldtool, null);

Listing 10: Add a domain to a field
// Assign a Domain to a Field
Geoprocessor GP = new Geoprocessor();
AssignDomainToField domainToField = new AssignDomainToField(@"C:\nfld.gdb\wells", "Diameter", "Diameter");

// Execute the tool
IGeoprocessorResult result = (IGeoProcessorResult ) GP.Execute(domainToField, null);

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++