Engine中如何更改lyr文件数据源的相对路径
以下是使用relativebase存储layerfile的代码,如果需要修改数据源只要修改ILayer即可:
string folderpath = @E:相对路径; string layerfilepath = @E:相对路径layer; ILayer layer = axMapControl1.get_Layer(0); IDataLayer2 pDataLayer = layer as IDataLayer2; pDataLayer.RelativeBase = folderpath + + layer.Name; ILayerFile pLayerFile = new LayerFileClass(); pLayerFile.New(layerfilepath + .lyr); pLayerFile.ReplaceContents(layer); pLayerFile.Save();