---
title: "How do you copy a file from one location to another in C#?"  
description: "How do you copy a file from one location to another in C#?"  
author: "ICSM Computer"  
published: 2025-05-05  
updated: 2025-05-19  
canonical: https://www.mindstick.com/forum/161573/how-do-you-copy-a-file-from-one-location-to-another-in-c-sharp  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# How do you copy a file from one location to another in C#?

How do you [copy](https://www.mindstick.com/forum/161993/explain-the-numpy-array-copy-vs-view-with-example) a [file](https://www.mindstick.com/articles/59/encrypting-and-decrypting-files-using-c-sharp) from one [location](https://www.mindstick.com/blog/11636/relocating-business-or-office-to-another-location) to another in C#?

## Replies

### Reply by Anubhav Sharma

In C#, you can copy a file from one location to another using the `File.Copy` method from the `System.IO` namespace.

### Syntax:

```cs
File.Copy(string sourceFileName, string destFileName, bool overwrite);
```

1. `sourceFileName`: Full path to the file you want to copy.
2. `destFileName`: Full path where you want the file copied.
3. `overwrite` (optional): Set to `true` if you want to overwrite the destination file if it exists.

### Example 1: Copy without overwrite

```cs
using System.IO;
File.Copy(@"C:\source\file.txt", @"C:\destination\file.txt");
```

This throws an exception if the destination file already exists.

### Example 2: Copy with overwrite

```cs
File.Copy(@"C:\source\file.txt", @"C:\destination\file.txt", true);
```

This replaces the destination file if it already exists.

### Exceptions to handle (optionally):

1. `FileNotFoundException`: If the source file doesn't exist.
2. `IOException`: If the destination file exists and `overwrite` is `false`.
3. `UnauthorizedAccessException`: If access is denied (e.g., permissions).
4. `DirectoryNotFoundException`: If the path is invalid.


---

Original Source: https://www.mindstick.com/forum/161573/how-do-you-copy-a-file-from-one-location-to-another-in-c-sharp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
