Please see below the function I have for writing a layer file. I'd like to embedded a version number that would be accessible on the Ilayer loaded into ArcMap (from the layer file). The intention being, that we could force symbology updates on existing MXDs by checking the version and reloading \ updating where necessary.
Any help with how to include the version number would be appreciated.
Public Function SaveToLayerFile(ByVal layerFilePath As System.String, ByVal layer As ESRI.ArcGIS.Carto.ILayer) As String Try If layer Is Nothing Then Return "Null Layer" End If
'create a new LayerFile instance Dim layerFile As ESRI.ArcGIS.Carto.ILayerFile = New ESRI.ArcGIS.Carto.LayerFileClass
'make sure that the layer file name is valid If System.IO.Path.GetExtension(layerFilePath) <> ".lyr" Then Return "Bad Path" End If
If layerFile.IsPresent(layerFilePath) Then System.IO.File.Delete(layerFilePath) End If
'create a new layer file layerFile.New(layerFilePath)
'attach the layer file with the actual layer layerFile.ReplaceContents(layer)
'save the layer file layerFile.Save() Catch ex As Exception Return ex.Message End Try
A layer file is a serialized layer object so there isn't any way to add to it without creating a new file format (which would no longer be readable as a layer file). You also cannot add to the layer object itself without creating your own layer type. You could use a property on an interface that is already implemented by the layer object. For example, you might use ILayerGeneralProperties.LayerDescription to hold the version number.