Layer file versioning

670
3
07-29-2013 06:18 AM
ChrisMatthews
New Contributor III
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.

Thanks

Chris



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

        Return "Success"
    End Function
0 Kudos
3 Replies
NeilClemmons
Regular Contributor III
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.
0 Kudos
ChrisMatthews
New Contributor III
Neil

If I created an object in my extension to hold the version seperately, is it possible to make this object persist in the MXD?


Regards

Chris
0 Kudos
NeilClemmons
Regular Contributor III
Yes, you can implement IPersistVariant on your extension class.
0 Kudos