How to delete all content


This tip demonstrates how to delete all metadata content without having to delete the metadata XML file on the file system or the metadata record in the geodatabase administration table. The Esri section with the metadata's unique identifier, its creation date, and any geocoding information is left intact - future updates will not replace this information.
This macro doesn't verify that the selected object supports metadata, whether it already has metadata, or whether the metadata is writable.

How to use

  1. Paste this macro into VBA.
  2. Select an object in ArcCatalog that has metadata.
  3. Run the macro.
[VBA]
Sub DeleteAllContent()
    
    Dim pGxApp As IGxApplication
    Dim pGxView As IGxView
    Dim pMD As IMetadata
    Dim pPS As IPropertySet
    Dim dNow As Date
    
    Set pGxApp = Application
    Set pMD = pGxApp.SelectedObject
    Set pPS = pMD.Metadata
    
    ' delete all metadata elements except the Esri section,
    ' which contains the identified elements
    pPS.RemoveProperty "*[not (MetaID or CreaDate or CreaTime or ModDate or ModTime or SyncOnce or RematchLocator)]"
    ' remove the elements indicating when the metadata was
    ' last synchronized
    pPS.RemoveProperty "Esri/SyncDate"
    pPS.RemoveProperty "Esri/SyncTime"
    ' set the SyncOnce element to True - next time the metadata
    ' is updated, the FGDC documentation hints will be added
    pPS.SetProperty "Esri/SyncOnce", "TRUE"
    
    ' set the time that the metadata was modified, then
    ' save the changes
    dNow = Now
    pPS.SetProperty "Esri/ModDate", Format(dNow, "yyyymmdd")
    pPS.SetProperty "Esri/ModTime", Format(dNow, "HhNnSs") & "00"
    pMD.Metadata = pPS
    
    Set pGxView = pGxApp.View
    If TypeOf pGxView Is IGxDocumentationView Then
        pGxView.Refresh
    End If
    
End Sub