ArcGIS Pro 3.7 API Reference Guide
ArcGIS.Core.Data Namespace / Attachment Class / GetAttachmentID Method
Example

In This Topic
    GetAttachmentID Method
    In This Topic
    Gets the object ID of the attachment. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    Public Function GetAttachmentID() As Long
    public long GetAttachmentID()

    Return Value

    The object ID of the attachment.
    Exceptions
    ExceptionDescription
    A geodatabase-related exception has occurred.
    This method or property must be called within the lambda passed to QueuedTask.Run
    Example
    Deleting Attachments
    {
      await 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 Home, Pro, Enterprise (64 bit)

    ArcGIS Pro version: 3.0 or higher.
    See Also