ArcGIS Pro 3.6 API Reference Guide
ArcGIS.Desktop.Mapping Namespace / BulkLayerCreationParams Class / RollbackBehavior Property
Example

In This Topic
    RollbackBehavior Property
    In This Topic
    Gets and sets the rollback behavior of the LayerFactory.CreateLayers method. This property only applies if the BulkLayerCreationParams is created with BulkLayerCreationParams Constructor(IEnumerable<LayerCreationParams>), otherwise it is ignored. Default value is LayerCreationRollbackBehavior.NoRollback.
    Syntax
    public LayerCreationRollbackBehavior RollbackBehavior {get; set;}
    Public Property RollbackBehavior As LayerCreationRollbackBehavior
    Remarks
    The bulk layer creation process creates the layers it is able to per the data supplied. If invalid Uris, data connections or Items exist amongst valid data, there will be a mismatch in the number of layers created compared to the number of data items supplied. For example, 5 Uris are supplied, but only 4 layers are created because one of the Uris points to a dataset that does not exist. LayerFactory.CreateLayers will return the layers created, but no information regarding the invalid dataset. The only exception to this is if all datasets are invalid (and no layers are created); in this scenario an System.ArgumentException will be thrown.

    When a set of LayerCreationParams objects exist, the bulk layer creation process applies the appropriate individual layer properties to the created layers. However if there is a mismatch between the number of data items supplied and the number of layers created, there may be situations where this is not possible and the layers created will not have the individual properties applied.

    Use this property to control the behavior of bulk layer creation in these scenarios.

    If set to LayerCreationRollbackBehavior.NoRollback then no rollback will occur regardless of whether all layers are created and all layer properties are applied.

    If set to LayerCreationRollbackBehavior.RollbackOnMissingLayers and there are instances where some layers cannot be created, then the layers that have been created will be removed and the end result will be that no new layers will be added to the TOC.

    If set to LayerCreationRollbackBehavior.RollbackOnCannotApplyLayerProperties and there are instances where some layers cannot be created, AND the individual layer properties cannot be applied to the created layers, then the layers that have been created will be removed and the end result will be that no new layers will be added to the TOC.

    Example
    Create multiple layers with BulkLayerCreationParams - Using RollbackBehavior
    var uriShp = new Uri(@"c:\data\roads.shp");
    var uriSde = new Uri(@"c:\MyDataConnections\MySDE.sde\Census");
    var uri = new Uri(@"http://sampleserver6.arcgisonline.com/arcgis/rest/services/NapervilleShelters/FeatureServer/0");
    
    var lcpShp = new FeatureLayerCreationParams(uriShp);
    lcpShp.Name = "Roads";
    lcpShp.IsVisible = false;
    lcpShp.DefinitionQuery = new DefinitionQuery("shpQuery", "OBJECTID > 10");
    
    var lcpSde = new FeatureLayerCreationParams(uriSde);
    lcpSde.Name = "Census Polygons";
    lcpSde.IsVisible = true;
    
    var lcpService = new FeatureLayerCreationParams(uri);
    lcpService.Name = "Shelters";
    lcpService.IsVisible = true;
    // set some renderer here ...
    //lcpService.RendererDefinition = ...
    
    var lcps = new List<FeatureLayerCreationParams>();
    lcps.Add(lcpShp);
    lcps.Add(lcpSde);
    lcps.Add(lcpService);
    
    var blkParams = new BulkLayerCreationParams(lcps);
    // set the positioning on the BulkLayerCreationParams
    blkParams.MapMemberPosition = MapMemberPosition.Index;
    blkParams.MapMemberIndex = 0;
    
    // set the rollback behavior
    // - rollback if one or more layers cannot be created due to an invalid data source
    blkParams.RollbackBehavior = LayerCreationRollbackBehavior.RollbackOnMissingLayers;
    
    var layers = LayerFactory.Instance.CreateLayers(blkParams, MapView.Active.Map);
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3.6 or higher.
    See Also