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. This sample is a stand-alone application, that in addition to providing the ability to save layer files, also implements a context menu, which pops up when right-clicking 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.

Development licensing Deployment licensing
Engine Developer Kit Engine Runtime
ArcView ArcView
ArcEditor ArcEditor
ArcInfo ArcInfo

How to use

See Using the samples for help on compiling, setting up the debugger, and running the sample (either an exe or dll).

  1. Open the solution using Visual Studio 2005.
  2. Build the solution.
  3. Press F5 to run the MapControl application.
  4. Use the AddData command to add a dataset to the map, or as an alternative, use the Add MapDocument to add an existing MapDocument to the map.
  5. Right-click a layer in the TOC to pop up the context menu.
  6. Click the Create Layer File command to save the current layer with its current renderer as a layer file.
  7. You can 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