Hi there,
I have written some code which exports a feature class in the TOC to a shapefile and a layer file. However when I copy the output results to a different location it seems the layer file's data source is still looking at the original location. The shapefile changes its data source to the new location but the layer file doesn't.
What I am looking to do is run my code, get the shapefile and layer file outputs and pass them to work mates. There are hundreds of outputs so I would like to automate this process. But as it stands my work mates would have to manually repair the data source for each and every broken layer file I give them.
I suspect it might be an issue regarding relative path names or resetting the data source of the layer file but I'm just not sure how to go about either option as I am new to VBA and learning as I go.
My code so far is ...
'Create layer file
Dim pGxLayer As IGxLayer
Dim pGxfile As IGxFile
Set pGxLayer = New GxLayer
Set pGxfile = pGxLayer
pGxfile.Path = "D:\GEOLOGY_REGIONAL_JULY2011\BOWEN BASIN\ESRI Shapefile\MyLayer.lyr"
Set pGxLayer.layer = pMap.layer(0)
Set pGxfile = Nothing
Set pGxLayer = Nothing
'Set data source of layer file
Set pGxLayer = New GxLayer
Set pGxfile = pGxLayer
Dim pDLayer As IDataLayer2
Set pDLayer = pGxLayer.Layer
Dim pDSName As IDatasetName
Set pDSName = pDLayer.DataSourceName
Debug.Print "old path : " & pDSName.WorkspaceName.PathName
Dim pWSName As IWorkspaceName
Set pWSName = pDSName.WorkspaceName
pWSName.PathName = 'I'm not sure what to put here I've tried
Debug.Print "new path: " & pDSName.WorkspaceName.PathName
pDLayer.DataSourceName = pDSName
Set pGxLayer.Layer = pDLayer
pGxfile.Save
For the new path name or to set the path name to relative I'm not sure what to put in ...
"\GEOLOGY_REGIONAL_JULY2011\BOWEN BASIN\ESRI Shapefile\MyLayer.lyr"
".\GEOLOGY_REGIONAL_JULY2011\BOWEN BASIN\ESRI Shapefile\MyLayer.lyr"
And neither of these works ...
Any help would be greatly appreciated. Thanks so much.
m