ArcGIS Pro 3.0 API Reference Guide
ArcGIS.Core.Data Namespace / Row Class / GetAttachments Method
An optional parameter. If not set or set to null, all attachments associated with this row is returned. Otherwise, only the attachments associated with the valid ID in attachmentIDs is returned.
An optional parameter. If not set or set to false, the entire attachment, including its binary data, is returned.
Example

In This Topic
    GetAttachments Method (Row)
    In This Topic
    Gets a IReadOnlyList of attachments based on the requested attachmentIDs for a given row. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    Public Function GetAttachments( _
       Optional ByVal attachmentIDs As IEnumerable(Of Long), _
       Optional ByVal infoOnly As Boolean _
    ) As IReadOnlyList(Of Attachment)

    Parameters

    attachmentIDs
    An optional parameter. If not set or set to null, all attachments associated with this row is returned. Otherwise, only the attachments associated with the valid ID in attachmentIDs is returned.
    infoOnly
    An optional parameter. If not set or set to false, the entire attachment, including its binary data, is returned.

    Return Value

    A IReadOnlyList of Attachment. If there are no attachments, an empty list.
    Exceptions
    ExceptionDescription
    The table or feature class has not been enabled for attachment creation.
    A geodatabase-related exception has occurred.
    Example
    Updating Attachments
    public async Task UpdatingAttachments()
    {
      await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
      {
        using (Geodatabase geodatabase = new Geodatabase(new DatabaseConnectionFile(new Uri("path\\to\\sde\\file\\sdefile.sde"))))
        using (FeatureClass landUseCaseFeatureClass = geodatabase.OpenDataset<FeatureClass>("LocalGovernment.GDB.LandUseCase"))
        {
          QueryFilter filter = new QueryFilter { WhereClause = "CASETYPE = 'Rezoning'" };
    
          using (RowCursor landUseCursor = landUseCaseFeatureClass.Search(filter, false))
          {
            while (landUseCursor.MoveNext())
            {
              using (Feature rezoningUseCase = (Feature)landUseCursor.Current)
              {
                IReadOnlyList<Attachment> rezoningAttachments = rezoningUseCase.GetAttachments();
                IEnumerable<Attachment> filteredAttachments = rezoningAttachments.Where(attachment => !attachment.GetName().Contains("rezoning"));
    
                foreach (Attachment attachmentToUpdate in filteredAttachments)
                {
                  attachmentToUpdate.SetName(attachmentToUpdate.GetName().Replace(".pdf", "Rezoning.pdf"));
                  rezoningUseCase.UpdateAttachment(attachmentToUpdate);
                }
              }
            }
          }
        }
      });
    }
    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"));
    
                var 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, Windows 8.1

    See Also