C# FileInfo MoveTo

Description

FileInfo MoveTo Moves a specified file to a new location, providing the option to specify a new file name.

Syntax

FileInfo.MoveTo has the following syntax.


public void MoveTo(
  string destFileName
)

Parameters

FileInfo.MoveTo has the following parameters.

  • destFileName - The path to move the file to, which can specify a different file name.

Returns

FileInfo.MoveTo method returns

Example

The following example demonstrates moving a file to a different location and renaming the file.


// ww  w .jav a2  s .com

using System;
using System.IO;
using System.Security.AccessControl;

class FileExample
{
    public static void Main()
    {
        string FileName = @"c:\MyTest.txt";
        FileInfo fInfo = new FileInfo(FileName);
        fInfo.MoveTo(@"c:\a\MyTest.txt");

    }
}




















Home »
  C# Tutorial »
    System.IO »




BinaryReader
BinaryWriter
Directory
DirectoryInfo
DriveInfo
File
FileInfo
FileStream
MemoryStream
Path
StreamReader
StreamWriter
StringReader
StringWriter