ArcGIS Pro 3.2 API Reference Guide
ArcGIS.Core.Data Namespace / Attachment Class / GetContentType Method
Example

In This Topic
    GetContentType Method
    In This Topic
    Gets the MIME type of the attached document. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    public string GetContentType()
    Public Function GetContentType() As String

    Return Value

    The MIME type of the attached document.
    Exceptions
    ExceptionDescription
    A geodatabase-related exception has occurred.
    This method or property must be called within the lambda passed to QueuedTask.Run
    Remarks
    The MIME type should match the extension on the name of the attachment data provided. It can be any string provided. However, for applications in the ArcGIS platform to correctly open the attachment it must match the attached document. For example, to attach a png image file named 'FireTruck09.png', the ContentType would be: 'image/png'.
    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