---
title: "how to delete file from directory in c#"  
description: "how to delete file from directory in c#"  
author: "Anonymous User"  
published: 2018-07-07  
updated: 2018-07-07  
canonical: https://www.mindstick.com/forum/34590/how-to-delete-file-from-directory-in-c-sharp  
category: "c#"  
tags: ["file", "delete"]  
reading_time: 2 minutes  

---

# how to delete file from directory in c#

please help me.

## Replies

### Reply by Prakash nidhi Verma

```
Use this below code :
```

```
public class SimpleFileMove
{
    static void Main()
    {
        string sourceFile = @"C:\Users\Public\public\mindstick.txt";
        string destinationFile = @"C:\Users\Public\private\mindstick.txt";
        // To move a file or folder to a new location:
        System.IO.File.Move(sourceFile, destinationFile);
        // To move an entire directory. To programmatically modify or combine
        // path strings, use the System.IO.Path class.
        System.IO.Directory.Move(@"C:\Users\Public\public\mindstick\", @"C:\Users\Public\private");
    }
```

### Reply by Anonymous User

use following code for deleting file and directory both.

```
        try            {                var FilePath=@"C:\\Temp\\ABC.TXT";                if (System.IO.File.Exists(FilePath))                {                    System.IO.File.Delete(FilePath);                    Directory.Delete(FilePath.Substring(0, FilePath.LastIndexOf('\\')));                }            }            catch (Exception ex)            {                Debug.WriteLine(ex.Message);            } 
```


---

Original Source: https://www.mindstick.com/forum/34590/how-to-delete-file-from-directory-in-c-sharp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
