I have an ArcObject Dissolve procedure that creates a shp in a directory. This dissolved layer is a temp layer and is not added into ArcMap. I would like to delete it when the user clicks a button again, however it will not delete because their is a lock file (Dissolved.shp.6H8Z5D1.3448.1520.sr.lock) in the directory that happens after the dissolve gp runs:
pSumTable = pGeoProc.Dissolve(pInputTable, True, "ROUTE", "Dissolve.Shape, Minimum.ROUTE", pdatasetname2)
I looked at Using Scheme Locks, however I'm not using this layer to perform any edits. I also found this post on GIS SE, however it too does not seem to apply for my situation. How do I remove this sr lock file (my entire code below), while keeping the ArcMap session open?
Thanks
Try
'delete all temp files
Dim s As String
For Each s In System.IO.Directory.GetFiles("J:\20111030\GIS\Scripts\TempData2")
System.IO.File.Delete(s)
Next s
'dissolve route layer
Dim pMap As IMap
pMap = mxdoc.FocusMap
Dim pInputFeatLayer As IFeatureLayer
pInputFeatLayer = featurelayer
If pInputFeatLayer Is Nothing Then
MessageBox.Show("The testinline layer was not found")
Exit Sub
End If
Dim pInputTable As ITable
pInputTable = pInputFeatLayer
If pInputTable Is Nothing Then
MsgBox("Table QI failed")
Exit Sub
End If
If pInputTable.FindField("ROUTE") = -1 Then
MsgBox("There must be a field named MUSYM layer ")
Exit Sub
End If
Dim pInputFeatClass As IFeatureClass
pInputFeatClass = featurelayer.FeatureClass
Dim pfeatureclassname As IFeatureClassName
pfeatureclassname = New FeatureClassName
With pfeatureclassname
.FeatureType = esriFeatureType.esriFTSimple
.ShapeFieldName = "Shape"
.ShapeType = pInputFeatClass.ShapeType
End With
Dim pNewWSName As IWorkspaceName
pNewWSName = New WorkspaceName
pNewWSName.WorkspaceFactoryProgID = "esriCore.ShapefileWorkspaceFactory.1"
pNewWSName.PathName = "J:\20111030\GIS\Scripts\TempData2\"
Dim pdatasetname2 As IDatasetName
pdatasetname2 = pfeatureclassname
pdatasetname2.Name = "Dissolved"
pdatasetname2.WorkspaceName = pNewWSName
Dim pGeoProc As IBasicGeoprocessor
Dim pSumTable As ITable
pGeoProc = New BasicGeoprocessor
pSumTable = pGeoProc.Dissolve(pInputTable, True, "ROUTE", "Dissolve.Shape, Minimum.ROUTE", pdatasetname2)
Dim pOutputFeatClass As IFeatureClass
pOutputFeatClass = pSumTable
If pOutputFeatClass Is Nothing Then
MsgBox("FeaturesClass QI Failed")
Exit Sub
End If
Dim pOutputFeatLayer As IFeatureLayer
pOutputFeatLayer = New FeatureLayer
pOutputFeatLayer.FeatureClass = pOutputFeatClass
pOutputFeatLayer.Name = pOutputFeatClass.AliasName
' CLEAN UP
featurelayer = Nothing
pInputFeatLayer = Nothing
pInputTable = Nothing
pInputFeatClass = Nothing
pfeatureclassname = Nothing
pNewWSName = Nothing
pdatasetname2 = Nothing
pGeoProc = Nothing
pSumTable = Nothing
pOutputFeatClass = Nothing
pOutputFeatLayer = Nothing
pMap = Nothing
mxdoc = Nothing
Catch ex As Exception
MessageBox.Show("Caught an unspecified error in the calling code: " & vbCrLf & ex.ToString)
End Try