how to delete file from directory in c#

Total Post:3

Points:21
File  delete 
C#
 100  View(s)
Ratings:
Rate this:

please help me.

  1. Post:280

    Points:1994
    Re: how to delete file from directory in c#

    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);
                } 

      Modified On Jul-07-2018 02:58:57 AM
  1. Post:140

    Points:984
    Re: how to delete file from directory in c#

    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");
        }

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!