string pfname = @"E:\Image\" + filename + ".jpg"; string BackUp=@"E:\BackupImage\" + filename + "1.jpg"; MemoryStream ms = new MemoryStream(image); Image returnImage = Image.FromStream(ms); FileInfo ffi = new FileInfo(pfname); if (ffi.Exists) { //System.IO.FileInfo file = new System.IO.FileInfo(pfname); //System.IO.FileInfo f = file.CopyTo(pfname, true); //file.Delete(); ReplaceFile(pfname, pfname, BackUp); // System.IO.File.Delete(pfname); //System.IO.F } returnImage.Save(@"E:\Image\" + filename + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
public static void ReplaceFile(string FileToMoveAndDelete, string FileToReplace, string BackupOfFileToReplace) { File.Replace(FileToMoveAndDelete, FileToReplace, BackupOfFileToReplace, false); }
if (ffi.Exists) { ms.Close(); //System.IO.FileInfo file = new System.IO.FileInfo(pfname); //System.IO.FileInfo f = file.CopyTo(pfname, true); //file.Delete(); ReplaceFile(pfname, pfname, BackUp); // System.IO.File.Delete(pfname); //System.IO.F }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)