Move a file from one location to another
This program will move a file from one
location to another.
- Move() method of file class is used for file movement parpuse.
 - It takes two arguments, source and destination.
 - The File class is located within System.io namespace
 - To move entire directory we can use Move() method of Directory class.
 
    protected
void Page_Load(object
sender, EventArgs e)
    {
        string
sourceFile = @"C:\Users\Public\public\test.txt";
        string
destinationFile = @"C:\Users\Public\private\test.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\test\",
@"C:\Users\Public\private");
    }
No comments:
Post a Comment