Export (0) Print
Expand All

File.Move Method

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

Namespace:  System.IO
Assembly:  mscorlib (in mscorlib.dll)

static member Move : 
        sourceFileName:string * 
        destFileName:string -> unit

Parameters

sourceFileName
Type: System.String

The name of the file to move.

destFileName
Type: System.String

The new path for the file.

ExceptionCondition
IOException

The destination file already exists.

-or-

sourceFileName was not found.

ArgumentNullException

sourceFileName or destFileName is a null reference (Nothing in Visual Basic).

ArgumentException

sourceFileName or destFileName is a zero-length string, contains only white space, or contains invalid characters as defined in InvalidPathChars.

UnauthorizedAccessException

The caller does not have the required permission.

PathTooLongException

The specified path, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters.

DirectoryNotFoundException

The path specified in sourceFileName or destFileName is invalid, (for example, it is on an unmapped drive).

NotSupportedException

sourceFileName or destFileName is in an invalid format.

This method works across disk volumes, and it does not throw an exception if the source and destination are the same. Note that if you attempt to replace a file by moving a file of the same name into that directory, you get an IOException. You cannot use the Move method to overwrite an existing file.

The sourceFileName and destFileName arguments are permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory. To obtain the current working directory, see GetCurrentDirectory.

If you try to move a file across disk volumes and that file is in use, the file is copied to the destination, but it is not deleted from the source.

For a list of common I/O tasks, see Common I/O Tasks.

The following example moves a file.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone 8, Silverlight 8.1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft