---
title: "How to Check if an Attachment Exists"
url: "https://docs.ravendb.net/6.2/client-api/session/how-to/check-if-attachment-exists"
version: "6.2"
language: "csharp"
---

# How to Check if an Attachment Exists

> Client language: C#. Also available for [Java](https://docs.ravendb.net/6.2/client-api/session/how-to/check-if-attachment-exists.java.md), [Python](https://docs.ravendb.net/6.2/client-api/session/how-to/check-if-attachment-exists.python.md), [PHP](https://docs.ravendb.net/6.2/client-api/session/how-to/check-if-attachment-exists.php.md), [Node.js](https://docs.ravendb.net/6.2/client-api/session/how-to/check-if-attachment-exists.nodejs.md).
>
> RavenDB publishes an official agent skill for coding assistants at https://docs.ravendb.net/skills/ravendb/SKILL.md (also installable with `npx skills add ravendb/skills`). The skill describes itself as: "Read this before writing any RavenDB query, client call or /databases/ request. Covers server setup, document modelling, the Node.js, .NET and Python clients, RQL, indexes, vector search and AI agents. Code written from recall tends to run and return the wrong rows, because RQL resembles SQL and the clients take field names as plain strings."

> **Note**
>
> - To check whether a document contains a certain attachment,  
>   use the method `Exists()` from the `Advanced.Attachments` session operations.
>
> - Calling *'Exists'* does not [Load](https://docs.ravendb.net/6.2/client-api/session/loading-entities.md) the document or the attachment to the session,  
>   and the session will not track them.
>
> - In this page:
>   - [Check if attachment exists](#check-if-attachment-exists)
>   - [Syntax](#syntax)

## Check if attachment exists

### Sync

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

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

### Async

```csharp
bool exists = await asyncSession
  .Advanced
  .Attachments
  .ExistsAsync("categories/1-A", "image.jpg");

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

## Syntax

### Sync

```csharp
bool Exists(string documentId, string attachmentName);
```

### Async

```csharp
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<br />`false` - The attachment does not exist on the document |

## See also

- [What is a Session and How Does it Work](https://docs.ravendb.net/6.2/client-api/session/what-is-a-session-and-how-does-it-work.md)
- [Loading Entities](https://docs.ravendb.net/6.2/client-api/session/loading-entities.md)
- [How to Check if Entity has Changed](https://docs.ravendb.net/6.2/client-api/session/how-to/check-if-entity-has-changed.md)
- [How to Check if There are Any Changes on a Session](https://docs.ravendb.net/6.2/client-api/session/how-to/check-if-there-are-any-changes-on-a-session.md)
- [Evict Entity From a Session](https://docs.ravendb.net/6.2/client-api/session/how-to/evict-entity-from-a-session.md)
- [Refresh Entity](https://docs.ravendb.net/6.2/client-api/session/how-to/refresh-entity.md)
