ArcGIS Pro 2.7 API Reference Guide
CreateLayer(Uri,ILayerContainerEdit,LayerPosition,String) Method
Example 

ArcGIS.Desktop.Mapping Namespace > LayerFactory Class > CreateLayer Method : CreateLayer(Uri,ILayerContainerEdit,LayerPosition,String) Method
An URI represents the path or url to a dataset or .lyrx or .lpkx file.
A map or group layer instance to which the Layer will be added
LayerPosition specifies whether the layer should be auto positioned or be on the top or at the bottom
(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, _
   Optional ByVal position As LayerPosition, _
   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 to which the Layer will be added
position
LayerPosition specifies whether the layer should be auto positioned or be on the top or at the bottom
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);
FeatureLayer flyr = (FeatureLayer)LayerFactory.Instance.CreateLayer(new Uri(@"C:\Data\Census.gdb\UnitedStatesFD\States"), MapView.Active.Map);
RasterLayer rlyr = (RasterLayer)LayerFactory.Instance.CreateLayer(new Uri(@"\\Machine\SharedFolder\Imagery.tif"), MapView.Active.Map);
FeatureLayer flyr = (FeatureLayer)LayerFactory.Instance.CreateLayer(new Uri(@"C:\Data\Fires.lyrx"), MapView.Active.Map);
Requirements

Target Platforms: Windows 10, Windows 8.1

See Also

Reference

LayerFactory Class
LayerFactory Members
Overload List