<?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: Delete a shapefile in ArcObjects SDK Questions</title>
    <link>https://community.esri.com/t5/arcobjects-sdk-questions/delete-a-shapefile/m-p/385682#M10223</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;After posting I found several references to deleting shapefiles on the older, retired forum which I think the VBA code you show was referenced.&amp;nbsp; I also found a reference to some code where the various file extensions of the files associated to a shapefile were stepped thru and deleted.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The shapefile that I want to delete from disk will not be opened at the time.&amp;nbsp; Looking at this VBA code it appears to be looking for an active layer to remove it from the map&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 28 Jan 2011 18:07:40 GMT</pubDate>
    <dc:creator>MarkParr</dc:creator>
    <dc:date>2011-01-28T18:07:40Z</dc:date>
    <item>
      <title>Delete a shapefile</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/delete-a-shapefile/m-p/385680#M10221</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Using ArcEngine, is there a call that I can pass the name of SHAPEFILE.SHP and have all the files associated w/ a shapefile deleted from disk?&amp;nbsp; If so, anyone have an example of the process.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I found the Delete class under ESRI.ArcGIS.DataManagementTools namespace that sounds like what I was looking for but no good examples of how to implement it.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 28 Jan 2011 14:45:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/delete-a-shapefile/m-p/385680#M10221</guid>
      <dc:creator>MarkParr</dc:creator>
      <dc:date>2011-01-28T14:45:56Z</dc:date>
    </item>
    <item>
      <title>Re: Delete a shapefile</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/delete-a-shapefile/m-p/385681#M10222</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;This is the old VBA code to delete the shapefile.&amp;nbsp; Add the appropriate references and modify the code to suit your needs in .NET.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;Private Sub DeleteDataset()
Dim pMxDocument As IMxDocument
Dim pMap As IMap
Dim pFeatureLayer As IFeatureLayer
Dim pFeatureClass As IFeatureClass
Dim pDataset As IDataset
Dim pActiveView As IActiveView
Set pMxDocument = ThisDocument
Set pMap = pMxDocument.FocusMap
' Define the dataset to be deleted.
Set pFeatureLayer = pMap.Layer(0)
Set pFeatureClass = pFeatureLayer.FeatureClass
' Remove the layer from the active map.
pMap.DeleteLayer pFeatureLayer
' Delete the dataset.
Set pDataset = pFeatureClass
pDataset.Delete
' Refresh the map.
Set pActiveView = pMap
pActiveView.Refresh
End Sub&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Cheers,&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 17:43:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/delete-a-shapefile/m-p/385681#M10222</guid>
      <dc:creator>RuchiraWelikala</dc:creator>
      <dc:date>2021-12-11T17:43:56Z</dc:date>
    </item>
    <item>
      <title>Re: Delete a shapefile</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/delete-a-shapefile/m-p/385682#M10223</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;After posting I found several references to deleting shapefiles on the older, retired forum which I think the VBA code you show was referenced.&amp;nbsp; I also found a reference to some code where the various file extensions of the files associated to a shapefile were stepped thru and deleted.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The shapefile that I want to delete from disk will not be opened at the time.&amp;nbsp; Looking at this VBA code it appears to be looking for an active layer to remove it from the map&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 28 Jan 2011 18:07:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/delete-a-shapefile/m-p/385682#M10223</guid>
      <dc:creator>MarkParr</dc:creator>
      <dc:date>2011-01-28T18:07:40Z</dc:date>
    </item>
    <item>
      <title>Re: Delete a shapefile</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/delete-a-shapefile/m-p/385683#M10224</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;That's correct.&amp;nbsp; The code above needs a layer assigned..but since you don't need that, try this code.&amp;nbsp; It's actually a snippet in included with the ESRI .NET SDK so it should be in your VS IDE.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ' This snippet is intended to be inserted at the base level of a Class.
&amp;nbsp;&amp;nbsp;&amp;nbsp; ' It is not intended to be nested within an existing Function or Sub.
&amp;nbsp;&amp;nbsp;&amp;nbsp; ' 

&amp;nbsp;&amp;nbsp;&amp;nbsp; '''&amp;lt;summary&amp;gt;Deletes from a specified directory that match a certain pattern.&amp;lt;/summary&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; ''' 
&amp;nbsp;&amp;nbsp;&amp;nbsp; '''&amp;lt;param name="filePath"&amp;gt;A System.String that is the file and path from where to delete files. Example: "C:\temp"&amp;lt;/param&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; '''&amp;lt;param name="pattern"&amp;gt; A System.String that is the pattern for files to delete. Example: "*.txt" or "myfile.*" or "*.*"&amp;lt;/param&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; '''&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; '''&amp;lt;remarks&amp;gt;All files meeting the pattern will be deleted from the specified directory.&amp;lt;/remarks&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Public Sub DeleteFilesFromDir(ByVal filePath As System.String, ByVal pattern As System.String)

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim directoryInfo As System.IO.DirectoryInfo = New System.IO.DirectoryInfo(filePath)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim files As System.IO.FileInfo() = directoryInfo.GetFiles(pattern)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; For Each file As System.IO.FileInfo In files
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; file.Delete()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Next

&amp;nbsp;&amp;nbsp;&amp;nbsp; End Sub&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 17:43:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/delete-a-shapefile/m-p/385683#M10224</guid>
      <dc:creator>RuchiraWelikala</dc:creator>
      <dc:date>2021-12-11T17:43:58Z</dc:date>
    </item>
    <item>
      <title>Re: Delete a shapefile</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/delete-a-shapefile/m-p/385684#M10225</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks for the suggestion.&amp;nbsp; That basic code appears to get everthing so it will need to be tweaked for just the files that make up the shapefile.&amp;nbsp; If I call DeleteShapefile(SHAPEFILE.SHP), I want to get that file and the .DBF, PRJ, etc but I don't want to delete SHAPEFILE.ZIP that might be out there.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I was hoping for a built-in ArcEngine call that would have handled that for me but I can work around that.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 28 Jan 2011 19:22:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/delete-a-shapefile/m-p/385684#M10225</guid>
      <dc:creator>MarkParr</dc:creator>
      <dc:date>2011-01-28T19:22:55Z</dc:date>
    </item>
    <item>
      <title>Re: Delete a shapefile</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/delete-a-shapefile/m-p/385685#M10226</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Use IDataset.Delete as shown in the original reply.&amp;nbsp; Instead of getting a layer from the map just open the shapefile yourself using IFeatureWorkspace.OpenFeatureClass.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 28 Jan 2011 19:32:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/delete-a-shapefile/m-p/385685#M10226</guid>
      <dc:creator>NeilClemmons</dc:creator>
      <dc:date>2011-01-28T19:32:03Z</dc:date>
    </item>
    <item>
      <title>Re: Delete a shapefile</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/delete-a-shapefile/m-p/385686#M10227</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Neil:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for the direction -- that's what I was looking for.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 28 Jan 2011 20:34:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/delete-a-shapefile/m-p/385686#M10227</guid>
      <dc:creator>MarkParr</dc:creator>
      <dc:date>2011-01-28T20:34:39Z</dc:date>
    </item>
  </channel>
</rss>

