Session: How to Check if an Attachment Exists


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

  • This does not load the document or the attachment from the server, and it does not cause the session to track the document.

  • In this page:


Syntax

bool Exists(string documentId, string name);
Task<bool> ExistsAsync(string documentId, string name, CancellationToken token = default);
Parameter Type Description
documentId string The ID of the document you want to check for the attachment
name string The name of the attachment you want to check the document for
Return Value Description
bool Indicates whether the document has an attachment with the specified name

Example

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

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

if (exists)
{
    //do something
}