How to Check if an Attachment Exists


  • To check whether a document contains a certain attachment,
    use the method Exists() from the Advanced.Attachments session operations.

  • Calling 'Exists' does not Load the document or the attachment to the session,
    and the session will not track them.

  • In this page:


Check if attachment exists

bool exists = session
    .Advanced
    .Attachments
    .Exists("categories/1-A", "image.jpg");

if (exists)
{
    // attachment 'image.jpg' exists on document 'categories/1-A'
}
bool exists = await asyncSession
    .Advanced
    .Attachments
    .ExistsAsync("categories/1-A", "image.jpg");

if (exists)
{
    // attachment 'image.jpg' exists on document 'categories/1-A'
}

Syntax

bool Exists(string documentId, string attachmentName);
Task<bool> ExistsAsync(string documentId, string attachmentName, CancellationToken token = default);
Parameter Type Description
documentId string The ID of the document you want to check
attachmentName string The name of the attachment you are looking for
Return Value Description
bool true - The specified attachment exists on the document
false - The attachment does not exist on the document