[GIS] Programmatically determine ArcGIS Layer(*.lyr) file version

arcmaparcobjects

I've been through IStorage, Microsoft Compound File Spec, ArcObjects deserialization etc. trying to detect the .lyr file version.

Using ArcObjects, I can get at the Layer properties, data source, extent, etc, but the documentVersion property of the LayerFileClass always reports back 'esriArcGISVersion10' on 9.3 Layer files.

ILayerFile l = new LayerFileClass();
l.Open(fileName);
LayerFileClass t = (LayerFileClass)l;
string version = t.DocumentVersion.ToString();

Any help is appreciated.

Note this crusty forum post from 2007.

Best Answer

Once a layer file is loaded, it is the current version as opening upgrades it. The DocumentVersion property exists solely to set a version for save back to a prior version with the LayerFile class.

The actual document version is not written to a layer file. The only version information written is the internal persistence version of the object. This information can be extracted via structured storage but you'd need a lookup of this version number for every possible layer type (and you'd also need to extract the layer type guid to even tell the layer type).