ArcGIS Pro 3.4 API Reference Guide
ArcGIS.Core.Data Namespace / Row Class / DeleteAttachments Method
The attachment IDs of the attachment documents to be remove.
Example

In This Topic
    DeleteAttachments Method
    In This Topic
    Deletes attachment(s) provided by attachmentID that are associated with the row. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax

    Parameters

    attachmentIDs
    The attachment IDs of the attachment documents to be remove.

    Return Value

    A Dictionary that holds zero or more key/value pairs where the existence of each key represents the attachment ID and the value represents the exception that has occurred while deleting the attachment in the table or feature class. If the operation is successful, the returned Dictionary is empty.
    Exceptions
    ExceptionDescription
    The table or feature class has not been enabled for attachment creation.
    A geodatabase-related exception has occurred.
    Example
    Deleting Attachments
    public async Task DeletingAttachments()
    {
        await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
        {
            using (Geodatabase geodatabase = new Geodatabase(new DatabaseConnectionFile(new Uri("path\\to\\sde\\file\\sdefile.sde"))))
            using (Table inspectionTable = geodatabase.OpenDataset<Table>("luCodeInspection"))
            {
                QueryFilter queryFilter = new QueryFilter { WhereClause = "ACTION = '1st Notice'" };
    
                using (RowCursor cursor = inspectionTable.Search(queryFilter, false))
                {
                    while (cursor.MoveNext())
                    {
                        using (Row currentRow = cursor.Current)
                        {
                            IReadOnlyList<Attachment> rowAttachments = currentRow.GetAttachments(null, true);
                            IEnumerable<Attachment> attachments = rowAttachments.Where(attachment => attachment.GetContentType().Equals("application/pdf"));
    
                            IReadOnlyList<long> attachmentIDs = attachments.Select(attachment => attachment.GetAttachmentID()) as IReadOnlyList<long>;
                            IReadOnlyDictionary<long, Exception> failures = currentRow.DeleteAttachments(attachmentIDs);
    
                            if (failures.Count > 0)
                            {
                                //process errors
                            }
                        }
                    }
                }
            }
        });
    }
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also