Replace file contents in CSharp

Description

The following code shows how to replace file contents.

Example


using System;/*www.  ja  v  a2s.  c  o m*/
using System.IO;

class FileExample
{
    public static void Main()
    {
        string OriginalFile = "test.xml";
        string FileToReplace = "test2.xml";
        ReplaceFile(OriginalFile, FileToReplace, "test3.xml");
    }
    public static void ReplaceFile(string FileToMoveAndDelete, string FileToReplace, string BackupOfFileToReplace)
    {
        File.Replace(FileToMoveAndDelete, FileToReplace, BackupOfFileToReplace, false);

    }
}




















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