<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Shapefile LOCK files in ArcObjects SDK Questions</title>
    <link>https://community.esri.com/t5/arcobjects-sdk-questions/shapefile-lock-files/m-p/1038286#M20288</link>
    <description>&lt;P&gt;That was a great suggestion.&amp;nbsp; I had forgotten about IDataLayer2.&amp;nbsp; However, it did not work.&amp;nbsp; The lock file is still there.&amp;nbsp; I have noticed that the lock file isn't actually created when the layer is added to the map, but two lines earlier when the feature class is defined on the feature layer from pGxDataset.Dataset (for whatever help that is).&lt;/P&gt;</description>
    <pubDate>Thu, 18 Mar 2021 20:33:51 GMT</pubDate>
    <dc:creator>DaveLewis73</dc:creator>
    <dc:date>2021-03-18T20:33:51Z</dc:date>
    <item>
      <title>Shapefile LOCK files</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/shapefile-lock-files/m-p/474604#M12845</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have a WCF service that opens a collection of shapefiles and uploads the data from these shapefiles into their respective SDE feature classes.&amp;nbsp; Everything works perfectly except at the very end when I wish to delete the shapefiles as they are stored in a temporary location on the server. The act of opening a featurecursor on the shapefiles creates a LOCK file the same as if you were to view the file in ArcCatalog.&amp;nbsp; I do everything that I can possibly think of to release the lock on the shapefile, including System.Runtime.Interop.Marshal.ReleaseComObject &amp;amp; FinalReleaseComObject (neither works) on all ArcObjects that I use along with shutting down the ArcObjects license that I check out at the beginning of the whole procedure. I cannot find any hints as to how to release the lock on the shapefile.&amp;nbsp; It eventually goes away if I wait long enough, but I need for it to go away immediately after I am done looping through the feature cursor.&amp;nbsp; Does anyone have any ideas on how to release these locks? I tried to use the ESRI.ArcGIS.esriSystem.IAppLockMgr but I cannot find any examples on how to use this and I'm not even sure if it is the correct interface to use for this.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any help would be GREATLY appreciated.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks in advance,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;- Matt&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 03 Feb 2011 14:52:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/shapefile-lock-files/m-p/474604#M12845</guid>
      <dc:creator>MatthewMalinowski</dc:creator>
      <dc:date>2011-02-03T14:52:50Z</dc:date>
    </item>
    <item>
      <title>Re: Shapefile LOCK files</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/shapefile-lock-files/m-p/474605#M12846</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Is this an exclusive lock (.ex.lock) or a shared lock (.sr.lock)? I belive you can only release an exclusive lock. Also, I think shared locks are not release until the calling app is disposed....&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Feb 2011 13:13:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/shapefile-lock-files/m-p/474605#M12846</guid>
      <dc:creator>GregoryRoss</dc:creator>
      <dc:date>2011-02-16T13:13:40Z</dc:date>
    </item>
    <item>
      <title>Re: Shapefile LOCK files</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/shapefile-lock-files/m-p/474606#M12847</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Locks are caused by the interaction of ArcObjects COM and .NET framework.&amp;nbsp; You need to explicitly release any objects referring to the shapefile using the comreleaser.&amp;nbsp; This includes any cursor, feature, row, featureclass or workspace objects.&amp;nbsp; The locks will be released when the calling app is disposed because that will release all the objects.&amp;nbsp; If you explicitly release all the objects by calling comreleaser, you should be able to release the locks without terminating the process.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Feb 2011 16:24:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/shapefile-lock-files/m-p/474606#M12847</guid>
      <dc:creator>AlexanderGray</dc:creator>
      <dc:date>2011-02-16T16:24:16Z</dc:date>
    </item>
    <item>
      <title>Re: Shapefile LOCK files</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/shapefile-lock-files/m-p/1038162#M20284</link>
      <description>&lt;P&gt;I realize that this posting is 10 years old, so I might not get a response.&amp;nbsp; However,&amp;nbsp;&lt;SPAN&gt;I am having difficulty figuring out how to remove .sr lock files from shapefiles using ArcObjects and C# after removing the associated layer from the map. I notice that using the straight UI in ArcMap that removing a layer will remove the lock file, but I cannot get this to happen programmatically. I have tried everything that I can think of, including calling Marshal.FinalReleaseComObject on all variables.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Mar 2021 16:48:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/shapefile-lock-files/m-p/1038162#M20284</guid>
      <dc:creator>DaveLewis73</dc:creator>
      <dc:date>2021-03-18T16:48:16Z</dc:date>
    </item>
    <item>
      <title>Re: Shapefile LOCK files</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/shapefile-lock-files/m-p/1038258#M20285</link>
      <description>&lt;P&gt;The &lt;A href="https://desktop.arcgis.com/en/arcobjects/latest/net/webframe.htm#IMxDocument_OperationStack.htm" target="_blank" rel="noopener"&gt;IMxDocument.OperationStack&lt;/A&gt; might still have a reference to the layer.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Maybe try IOperationStack.Reset() to see if that clears the lock. You won't be able to Edit&amp;gt;Undo (ctrl-Z) to the layer removal after doing so.&lt;/P&gt;</description>
      <pubDate>Thu, 18 Mar 2021 19:50:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/shapefile-lock-files/m-p/1038258#M20285</guid>
      <dc:creator>KirkKuykendall1</dc:creator>
      <dc:date>2021-03-18T19:50:25Z</dc:date>
    </item>
    <item>
      <title>Re: Shapefile LOCK files</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/shapefile-lock-files/m-p/1038271#M20286</link>
      <description>&lt;P&gt;Kirk, thank you for the response.&amp;nbsp; I tried your suggestion and unfortunately it did not make a difference.&amp;nbsp; The only thing that seems to kill the .sr.lock files is manually shutting down the ArcMap application, which gets rid of all of the COM references.&amp;nbsp; However, this is not a solution, since I have so many directories worth of shapefiles to run through.&amp;nbsp; The following is a little snippet from my code to show the issue.&lt;/P&gt;&lt;P&gt;pGxObjects.Reset();&lt;/P&gt;&lt;P&gt;while ((pGxDataset = (IGxDataset)pGxObjects.Next()) != null)&lt;BR /&gt;{&lt;BR /&gt;IFeatureLayer pFeatLayer = new FeatureLayer();&lt;BR /&gt;pFeatLayer.FeatureClass = (IFeatureClass)pGxDataset.Dataset;&lt;BR /&gt;pFeatLayer.Name = pFeatLayer.FeatureClass.AliasName;&lt;BR /&gt;pMxDoc.FocusMap.AddLayer(pFeatLayer);&lt;/P&gt;&lt;P&gt;// Do something with the layer&lt;/P&gt;&lt;P&gt;pMxDoc.FocusMap.DeleteLayer(pFeatLayer);&lt;BR /&gt;Marshal.FinalReleaseComObject(pFeatLayer);&lt;BR /&gt;Marshal.FinalReleaseComObject(pGxDataset);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;Marshal.FinalReleaseComObject(pGxObjects);&lt;BR /&gt;GC.Collect();&lt;BR /&gt;GC.WaitForPendingFinalizers();&lt;/P&gt;</description>
      <pubDate>Thu, 18 Mar 2021 20:05:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/shapefile-lock-files/m-p/1038271#M20286</guid>
      <dc:creator>DaveLewis73</dc:creator>
      <dc:date>2021-03-18T20:05:43Z</dc:date>
    </item>
    <item>
      <title>Re: Shapefile LOCK files</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/shapefile-lock-files/m-p/1038279#M20287</link>
      <description>&lt;P&gt;Maybe before deleting the layer, try &lt;A href="https://desktop.arcgis.com/en/arcobjects/latest/net/webframe.htm#IDataLayer2_Disconnect.htm" target="_blank" rel="noopener"&gt;IDataLayer2.Disconnect()&lt;/A&gt; on it.&lt;/P&gt;</description>
      <pubDate>Thu, 18 Mar 2021 20:13:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/shapefile-lock-files/m-p/1038279#M20287</guid>
      <dc:creator>KirkKuykendall1</dc:creator>
      <dc:date>2021-03-18T20:13:22Z</dc:date>
    </item>
    <item>
      <title>Re: Shapefile LOCK files</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/shapefile-lock-files/m-p/1038286#M20288</link>
      <description>&lt;P&gt;That was a great suggestion.&amp;nbsp; I had forgotten about IDataLayer2.&amp;nbsp; However, it did not work.&amp;nbsp; The lock file is still there.&amp;nbsp; I have noticed that the lock file isn't actually created when the layer is added to the map, but two lines earlier when the feature class is defined on the feature layer from pGxDataset.Dataset (for whatever help that is).&lt;/P&gt;</description>
      <pubDate>Thu, 18 Mar 2021 20:33:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/shapefile-lock-files/m-p/1038286#M20288</guid>
      <dc:creator>DaveLewis73</dc:creator>
      <dc:date>2021-03-18T20:33:51Z</dc:date>
    </item>
    <item>
      <title>Re: Shapefile LOCK files</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/shapefile-lock-files/m-p/1038295#M20289</link>
      <description>&lt;P&gt;In general, I find it good practice to work with IName objects.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Maybe try replacing this:&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;pFeatLayer.FeatureClass = (IFeatureClass)pGxDataset.Dataset;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;with this:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;pFeatLayer.FeatureClass = ((IName)pGxDataset.DatasetName).Open() as IFeatureClass;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Mar 2021 20:47:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/shapefile-lock-files/m-p/1038295#M20289</guid>
      <dc:creator>KirkKuykendall1</dc:creator>
      <dc:date>2021-03-18T20:47:02Z</dc:date>
    </item>
    <item>
      <title>Re: Shapefile LOCK files</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/shapefile-lock-files/m-p/1038302#M20290</link>
      <description>&lt;P&gt;That was another good suggestion, but unfortunately I have the same result.&amp;nbsp; The .sr.lock file is created and I can't remove it.&lt;/P&gt;</description>
      <pubDate>Thu, 18 Mar 2021 20:56:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/shapefile-lock-files/m-p/1038302#M20290</guid>
      <dc:creator>DaveLewis73</dc:creator>
      <dc:date>2021-03-18T20:56:35Z</dc:date>
    </item>
    <item>
      <title>Re: Shapefile LOCK files</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/shapefile-lock-files/m-p/1038311#M20291</link>
      <description>&lt;P&gt;Does your pGxObjects represent a collection of shapefiles in a folder?&lt;/P&gt;&lt;P&gt;If so, I'd try opening the folder as a workspace make a List&amp;lt;IName&amp;gt; from IWorkspace.DatasetNames, and avoid using stuff in the Esri.Arcgis.Catalog altogether.&lt;/P&gt;&lt;P&gt;If you must use IGxCatalog,&amp;nbsp;&amp;nbsp;perhaps create a List&amp;lt;IName&amp;gt; from the pGxObjects, then call IGxCatalog.Close(), then loop through each name in the list.&lt;/P&gt;&lt;P&gt;I've always been suspicious of what IGxCatalog does behind the scenes - maybe for performance it's caching references(?)&lt;/P&gt;</description>
      <pubDate>Thu, 18 Mar 2021 21:21:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/shapefile-lock-files/m-p/1038311#M20291</guid>
      <dc:creator>KirkKuykendall1</dc:creator>
      <dc:date>2021-03-18T21:21:02Z</dc:date>
    </item>
    <item>
      <title>Re: Shapefile LOCK files</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/shapefile-lock-files/m-p/1038372#M20292</link>
      <description>&lt;P&gt;Kirk, I think that may have worked (or at least well enough).&amp;nbsp; I tested on a single folder with 15 shapefiles and all but one of the lock files went away.&amp;nbsp; I don't know what that is all about, but I will have to try and figure that out later.&amp;nbsp; I am just happy that I have made some progress.&amp;nbsp; Now, I just have to go through my enormous application and make all of the necessary changes, which will not be fun.&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Thu, 18 Mar 2021 22:48:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/shapefile-lock-files/m-p/1038372#M20292</guid>
      <dc:creator>DaveLewis73</dc:creator>
      <dc:date>2021-03-18T22:48:19Z</dc:date>
    </item>
  </channel>
</rss>

