This document is archived and information here might be outdated.  Recommended version.


Checking for existing data (ArcObjects .NET 10.4 SDK)

Checking for existing data


About checking for existing data

Programs often use paths to data, which can be problematic if the referenced data does not exist. Data might have been deleted or moved between executions of a script, which causes errors if the data is used in a geoprocessing tool's parameter. If there is a possibility of a referenced dataset not existing during a program's execution, the geoprocessor's Exists method should be used.
This method returns a Boolean value for the existence of a dataset or object at the time of execution. Objects (such as a cursor or spatial reference) managed by the geoprocessor can also be used as input to the Exists method. The Exists method works with any type of data available in ArcGS or with any system file or folder. A Catalog path must be used for this and any other geoprocessor method when referring to geographic information system (GIS) data. See the following code example:
[C#]
object dt="";
bool bExists=gp.Exists(@"C:\Data\PortlandOR.gdb\downtown", ref dt);
[VB.NET]
Dim dt As Object=""
Dim bExists As Boolean=gp.Exists("C:\Data\PortlandOR.gdb\downtown", dt)
If the data resides in an enterprise geodatabase, the name must be fully qualified. See How to qualify table and field names for more information.
The default behavior for all tools is to not to overwrite the output. This behavior can be changed by setting the OverWriteOutput environment to true. Attempting to overwrite when the OverWriteOutput option is false causes a tool to fail. See the following code example:
[C#]
gp.OverwriteOuptut=true;
[VB.NET]
gp.OverwriteOutput=True


See Also:

Using environment settings