I am trying to programmatically create a full copy of a layer on my map in ArcMap so that the user can run tools to clean up the data without mucking with the original in case they do something wrong. I have it working in ArcPro, but, because of speed issues, I am now trying to implement my cleanup tools in ArcMap. In ArcPro, my code looks like
var lyr = _arcFac.MainMapView.Map.GetLayersAsFlattenedList()
await QuededTask.Run(() =>
{
foreach (BasicFeatureLayer fmLyr in lyr) {
var hydLayer = fmLyr as FeatureLayer;
var hydClass = hydLayer .GetFeatureClass();
var hydStore = hydClass.GetDatastore();
var hydPath = Path.Combine(hydStore.GetPath().LocalPath, hydClass.GetName());
string newFileName = $"MergeLayer.shp";
var mva = Geoprocessing.MakeValueArray(hydPath + ".shp", $@"{hydPath}" newFileName);
var res2 = Geoprocessing.ExecuteToolAync("copy_Management", mva);
}
}
In ArcMap, I have
IFeatureLayer hydLayer = selectedLayer[0];
var hydClass = hydLayer .FeatureClass();
var hydStore = hydClass.FeatureDataset(); //this is null
So, how do I get the full path of the selected layers? File.GetPath(selectedLayer[0]) get the correct path only if it is in the same path as the map and if you have saved the map.
Thank you,
Susan
Try this code:
Public Sub GetPath()
' This sample code assumes the first layer in the map is a shapefile
Dim pMXD As IMxDocument
Set pMXD = ThisDocument
Dim pMap As IMap
Set pMap = pMXD.FocusMap
Dim pLayer As ILayer
Set pLayer = pMap.Layer(0)
Dim pDataset As IDataset
Set pDataset = pLayer
Dim sPath As String
Let sPath = pDataset.Workspace.PathName & "\" & pDataset.Name & ".shp"
MsgBox sPath, vbOKOnly, "Full Path"
End Sub