在程序中打开文件时备份文件的最有效方法是什么,以便当用户更改并保存它时,总有办法返回?
例子:
private void open_click(object sender, EventArgs e)
{
ofd.DefaultExt = "";
if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
fileIn = ofd.FileName;
fileOut = Path.GetTempFileName();
string encoded = File.ReadAllText(fileIn);
etc. etc. etc
}
加载到程序中的文件需要备份为 backup_01 并放在与原始文件相同的文件夹中。当backup_01存在时,备份为backup_02,以此类推)。
例子非常受欢迎!