---
title: "Attachments: Copy, Move, Rename"
url: "https://docs.ravendb.net/6.2/document-extensions/attachments/copying-moving-renaming"
version: "6.2"
language: "csharp"
---

# Attachments: Copy, Move, Rename

> Client language: C#. Also available for [Java](https://docs.ravendb.net/6.2/document-extensions/attachments/copying-moving-renaming.java.md), [Python](https://docs.ravendb.net/6.2/document-extensions/attachments/copying-moving-renaming.python.md), [PHP](https://docs.ravendb.net/6.2/document-extensions/attachments/copying-moving-renaming.php.md), [Node.js](https://docs.ravendb.net/6.2/document-extensions/attachments/copying-moving-renaming.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."

Attachments can be copied, moved, or renamed using built-in session methods.  
All of those actions are executed when `SaveChanges` is called and take place on the server-side,  
removing the need to transfer the entire attachment binary data over the network in order to perform the action.

## Copy attachment

Attachment can be copied using one of the `session.Advanced.Attachments.Copy` methods:

### Syntax

```csharp
void Copy(
  object sourceEntity,
  string sourceName,
  object destinationEntity,
  string destinationName);

void Copy(
  string sourceDocumentId,
  string sourceName,
  string destinationDocumentId,
  string destinationName);
```

### Example

#### Sync

```csharp
var employee1 = session.Load<Employee>("employees/1-A");
var employee2 = session.Load<Employee>("employees/2-A");

session.Advanced.Attachments.Copy(employee1, "photo.jpg", employee2, "photo-copy.jpg");

session.SaveChanges();
```

#### Async

```csharp
var employee1 = await asyncSession.LoadAsync<Employee>("employees/1-A");
var employee2 = await asyncSession.LoadAsync<Employee>("employees/2-A");

asyncSession.Advanced.Attachments.Copy(employee1, "photo.jpg", employee2, "photo-copy.jpg");

await asyncSession.SaveChangesAsync();
```

## Move attachment

Attachment can be moved using one of the `session.Advanced.Attachments.Move` methods:

### Syntax

```csharp
void Move(object sourceEntity, string sourceName, object destinationEntity, string destinationName);

void Move(string sourceDocumentId, string sourceName, string destinationDocumentId, string destinationName);
```

### Example

#### Sync

```csharp
var employee1 = session.Load<Employee>("employees/1-A");
var employee2 = session.Load<Employee>("employees/2-A");

session.Advanced.Attachments.Move(employee1, "photo.jpg", employee2, "photo.jpg");

session.SaveChanges();
```

#### Async

```csharp
var employee1 = await asyncSession.LoadAsync<Employee>("employees/1-A");
var employee2 = await asyncSession.LoadAsync<Employee>("employees/2-A");

asyncSession.Advanced.Attachments.Move(employee1, "photo.jpg", employee2, "photo.jpg");

await asyncSession.SaveChangesAsync();
```

## Rename attachment

Attachment can be renamed using one of the `session.Advanced.Attachments.Rename` methods:

### Syntax

```csharp
void Rename(object entity, string name, string newName);

void Rename(string documentId, string name, string newName);
```

### Example

#### Sync

```csharp
var employee = session.Load<Employee>("employees/1-A");

session.Advanced.Attachments.Rename(employee, "photo.jpg", "photo-new.jpg");

session.SaveChanges();
```

#### Async

```csharp
var employee = await asyncSession.LoadAsync<Employee>("employees/1-A");

asyncSession.Advanced.Attachments.Rename(employee, "photo.jpg", "photo-new.jpg");

await asyncSession.SaveChangesAsync();
```

## See also

- [What are Attachments](https://docs.ravendb.net/6.2/document-extensions/attachments/what-are-attachments.md)
- [Storing](https://docs.ravendb.net/6.2/document-extensions/attachments/storing.md)
- [Loading](https://docs.ravendb.net/6.2/document-extensions/attachments/loading.md)
- [Deleting](https://docs.ravendb.net/6.2/document-extensions/attachments/deleting.md)
