Save a layer file in a MapControl application


PurposeThis sample demonstrates how to create and save a layer file in a stand-alone ArcGIS Engine application. In addition to providing the ability to save layer files, this sample also implements a context menu that opens when you right-click a layer in the application's table of contents (TOC). This context menu hosts two commands: Save the current layer as a layer file and Remove the current layer from the map.

How to use

See How to use ArcGIS samples for help on compiling, setting up the debugger, and running the sample. If the sample has associated data, you will find that the sample's zip file includes a "data" folder alongside the language folders. However, you will need to update the sample to point to the location of the data once you have extracted all the files.

  1. Start Visual Studio, open the solution file, and build the project.
  2. Press F5 to run the MapControl application.
  3. Use the AddData command to add a dataset to the map, or as an alternative, use Add MapDocument to add an existing map document to the map.
  4. Right-click a layer in the TOC to open the context menu.
  5. Click the Create Layer File command to save the current layer with its current renderer as a layer file.
  6. Use the Load Layer File command to load the new layer to the map.

SaveLayerFileCmd.cs Save layer files command.
RemoveLayerCmd.cs Remove layer command.
LoadLayerFileCmd.cs Load layer command.
CreateNewDocument.cs Create new MapDocument command.
ContextMenuClass.cs Implementation file of the ContextMenu used by the application.
frmMain.cs Application's main dialog box form.
Download the C# files
SaveLayerFileCmd.vb Save layer files command.
RemoveLayerCmd.vb Remove layer command.
LoadLayerFileCmd.vb Load layer command.
CreateNewDocument.vb Create new MapDocument command.
ContextMenuClass.vb Implementation file of the ContextMenu used by the application.
frmMain.vb Application's main dialog box form.
Download the VB.NET files

Download the files for all languages

See Also:

How to save a layer file




Development licensing Deployment licensing
Engine Developer Kit Engine
ArcGIS for Desktop Basic
ArcGIS for Desktop Standard
ArcGIS for Desktop Advanced