Move a file in CSharp

Description

The following code shows how to move a file.

Example


         //  w  w  w  .  ja  v a  2s  .  com

using System;
using System.IO;

public class MainClass
{
  static void Main(string[] args)
  {
    FileInfo MyFile = new FileInfo(@"main.cs");

    MyFile.Create();
    MyFile.MoveTo(@"c:\MyFolder\Moved Testing.txt");
    MyFile.MoveTo(@"C:\MyFolderNew");
  }
}




















Home »
  C# Tutorial »
    IO »




File Attribute
File Security
Directory Attribute
Directory Recursive
Binary File
Text Field
Buffered IO
Create Copy Delete Move
CSV
Drive
File System Watcher
Isolated Storage
MemoryStream
Serialize
Zip