Saving a layer file
One of the main features of a layer is that it can exist outside your map as a file on disk. This makes it easy for others to access the layers you've built.
When you save a layer to disk, you save everything about the layer, such as the symbolization and labeling. When you add a layer file to another map, it will draw exactly as it was saved. Others can drop these layers onto their maps without having to know how to access the database or classify the data; this can be helpful when sharing data stored in a multiuser geodatabase with nontechnical staff members. You can share layers over a network and e-mail layers with the data or enclose the layer in the data's metadata.
To save layer files programmatically in an ArcGIS Engine application, do the following:
- Get the output path for the new layer file. The layer file must have a .lyr extension. See the following:
- Create a new instance of a LayerFile class—You will be using a LayerFile class to create a new instance of a layer file. See the following:
//Create a new LayerFile instance. ILayerFile layerFile = new LayerFile(); //Create a new layer file. layerFile.esri_new(fileName);
- Bind the layer from the map with the newly created layer file—Once you have created the new layer file, you need to bind it with the current layer from the map that you intend to save to disk. See the following:
//Bind the layer file with the layer from the map. layerFile.replaceContents(layer);
- Save the layer file—To complete the operation, you must save the layer file. See the following:
|Development licensing||Deployment licensing|
|Engine Developer Kit||Engine|
|ArcGIS for Desktop Basic||ArcGIS for Desktop Basic|
|ArcGIS for Desktop Standard||ArcGIS for Desktop Standard|
|ArcGIS for Desktop Advanced||ArcGIS for Desktop Advanced|