ArcGIS Pro 2.8 API Reference Guide
CreateLayer(Uri,ILayerContainerEdit,Int32,String) Method
Example 

ArcGIS.Desktop.Mapping Namespace > LayerFactory Class > CreateLayer Method : CreateLayer(Uri,ILayerContainerEdit,Int32,String) Method
An URI represents the path or url to a dataset or .lyrx or .lpkx file.
A map or group layer instance where the Layer will be added
The position of the layer in the map or group layer. 0 represents the top most position.
(optional) When it is not provided, the default display name gets used e.g. the dataset name or alias. (default value = "")
Creates a new Layer instance with the specified path to a dataset and adds it to a container such as a map or a group layer. Optionally you can provide a name to override the default display name. This method must be called on the MCT. Use QueuedTask.Run.
Syntax
Public Overloads Function CreateLayer( _
   ByVal dataUri As Uri, _
   ByVal mapOrGroupLayer As ILayerContainerEdit, _
   ByVal index As Integer, _
   Optional ByVal layerName As String _
) As Layer

Parameters

dataUri
An URI represents the path or url to a dataset or .lyrx or .lpkx file.
mapOrGroupLayer
A map or group layer instance where the Layer will be added
index
The position of the layer in the map or group layer. 0 represents the top most position.
layerName
(optional) When it is not provided, the default display name gets used e.g. the dataset name or alias. (default value = "")

Return Value

Exceptions
ExceptionDescription
This method or property must be called within the lambda passed to QueuedTask.Run.
Remarks

Some sample paths to:

A FeatureClass in a FileGeodatabase C:\Data\MyFileGDB.gdb\Census
A shape file in a folder \\Machine\SharedFolder\MySpatialData.dbf
A RasterDataset in a FileGeodatabase C:\Data\MyFileGDB.gdb\DEM
A FeatureClass from a SDE C:\Connections\MySDEConnection.sde\Roads
An image file in a folder \\Machine\SharedFolder\Imagery.tif
A .lyrx or .lpkx file \\Machine\SharedFolder\Fires.lyrx
A map service layer http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer
A feature layer off a map or feature service http://sampleserver6.arcgisonline.com/arcgis/rest/services/NapervilleShelters/FeatureServer/0

Example
FeatureLayer flyr = (FeatureLayer)LayerFactory.Instance.CreateLayer(new Uri(@"C:\Data\Census.gdb\States"), MapView.Active.Map, 0);
FeatureLayer flyr = (FeatureLayer)LayerFactory.Instance.CreateLayer(new Uri(@"C:\Data\Census.gdb\UnitedStatesFD\States"), MapView.Active.Map, 0);
RasterLayer rlyr = (RasterLayer)LayerFactory.Instance.CreateLayer(new Uri(@"\\Machine\SharedFolder\Imagery.tif"), MapView.Active.Map, 0);
FeatureLayer flyr = (FeatureLayer)LayerFactory.Instance.CreateLayer(new Uri(@"C:\Data\Fires.lyrx"), MapView.Active.Map, 0);
Requirements

Target Platforms: Windows 10, Windows 8.1

See Also

Reference

LayerFactory Class
LayerFactory Members
Overload List