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);
}
}