Q:

C# program to move file from one location to another location

0

Given a file, and we have to move it from one location to another location using C# program.

File.Move()

This is a method of "File class, which is used to move a file from one location (source) to another location (destination).

Syntax:

File.Move(source_file, dest_file);

Parameter(s):

  1. source_file - Location of source file.
  2. dest_file - Location of destination file, and here we can change filename.

We can set following detail of last write time:

  • Date
  • Month
  • Year
  • Hour
  • Minute
  • Second
  • AM/PM
  •  

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program

using System;
using System.IO;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main()
        {
           
            File.Move("source/ABC.TXT", "dest/XYZ.TXT");
            Console.WriteLine("File moved successfully");

        }
    }
}

Output

File moved successfully

Note: In above program, we need to remember, when we use "File" class, System.IO namespace must be included in the program.

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C# file handling (File class) solved programs/examples

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C# program to read all lines of a text file... >>
<< C# program to set last write time of file or direc...