ArcGIS Pro 3.7 API Reference Guide
ArcGIS.Desktop.Mapping Namespace / LayerDocument Class / Save Method
A string represents a file path.
Example

In This Topic
    Save Method
    In This Topic
    Save as a Layer File (.lyrx) This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    Public Sub Save( _
       ByVal layerXFilePath As String _
    ) 
    public void Save( 
       string layerXFilePath
    )

    Parameters

    layerXFilePath
    A string represents a file path.
    Exceptions
    ExceptionDescription
    This method or property must be called within the lambda passed to QueuedTask.Run.
    Example
    Create layer from a lyrx file
    {
        //Note: Call within QueuedTask.Run()
        var lyrDocFromLyrxFile = new LayerDocument(@"d:\data\cities.lyrx");
        var cimLyrDoc = lyrDocFromLyrxFile.GetCIMLayerDocument();
    
        //modifying its renderer symbol to red
        var cimSimpleRenderer = ((CIMFeatureLayer)cimLyrDoc.LayerDefinitions[0]).Renderer as CIMSimpleRenderer;
        cimSimpleRenderer?.Symbol.Symbol.SetColor(new CIMRGBColor() { R = 255 });
    
        //optionally save the updates out as a file
        lyrDocFromLyrxFile.Save(@"c:\data\cities_red.lyrx");
    
        //get a json representation of the layer document and you want store away...
        var aJSONString = lyrDocFromLyrxFile.AsJson();
    
        //... and load it back when needed
        lyrDocFromLyrxFile.Load(aJSONString);
        cimLyrDoc = lyrDocFromLyrxFile.GetCIMLayerDocument();
    
        //create a layer and add it to a map
        var lcp = new LayerCreationParams(cimLyrDoc);
        var lyr = LayerFactory.Instance.CreateLayer<FeatureLayer>(lcp, map);
    }
    Create a Lyrx file
    {
        LayerDocument layerDocument = new LayerDocument(layer);
        //Note: Run within QueuedTask
        layerDocument.Save(@"c:\Data\MyLayerDocument.lyrx");
    }
    Requirements

    Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)

    ArcGIS Pro version: 3.0 or higher.
    See Also