diff --git a/PROMS/VEPROMS User Interface/dlgExportImport.cs b/PROMS/VEPROMS User Interface/dlgExportImport.cs index 60e40a0f..955b5c78 100644 --- a/PROMS/VEPROMS User Interface/dlgExportImport.cs +++ b/PROMS/VEPROMS User Interface/dlgExportImport.cs @@ -232,6 +232,12 @@ namespace VEPROMS { // C2022-029 if an existing export of the same name is found, provide option to overwrite it DialogResult ovewriteEx = FlexibleMessageBox.ShowCustom(null, "There is already another export file with the same name. You can choose to either overwrite the existing file or have the existing file renamed with the original creation date appended.\r\n\r\nSelecting 'Cancel' will cancel the export.", "What would you like to do?", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);// == DialogResult.Yes; + // Extract directory, filename, and extension + string directory = Path.GetDirectoryName(fileLocation); + string filename = Path.GetFileNameWithoutExtension(fileLocation); + string extension = Path.GetExtension(fileLocation); + fileLocation = $"{directory}\\{filename}{extension}"; + if (ovewriteEx == DialogResult.Abort) { MessageBox.Show("Export has been cancelled", "You have chosen to cancel the export.", MessageBoxButtons.OK, MessageBoxIcon.Information); // C2020-042 changed mesage box title @@ -240,33 +246,17 @@ namespace VEPROMS } else if (ovewriteEx == DialogResult.Retry) { - // Ovewrite - // Extract directory, filename, and extension - string directory = Path.GetDirectoryName(fileLocation); - string filename = Path.GetFileNameWithoutExtension(fileLocation); - string extension = Path.GetExtension(fileLocation); - - fileLocation = $"{directory}\\{filename}{extension}"; + //Overwrite will occur, set msg. msg = "The export file has been overwritten. "; } else if (ovewriteEx == DialogResult.Ignore) { - // Extract directory, filename, and extension - string directory = Path.GetDirectoryName(fileLocation); - string filename = Path.GetFileNameWithoutExtension(fileLocation); - string extension = Path.GetExtension(fileLocation); - - // Generate the new filename with a datestamp - fileLocation = $"{directory}\\{filename}{extension}"; - - // Get the creation date of the existing file - DateTime creationDate = File.GetCreationTime(fileLocation); - - // Format the creation date to use it as a datestamp - string datestamp = creationDate.ToString("yyyyMMddHHmmss"); - + // Get the modified date of the existing file, create a datestamp for use in name, set newlocation to move to + DateTime modifiedDate = File.GetLastWriteTime(fileLocation); + string datestamp = modifiedDate.ToString("yyyyMMddHHmmss"); string newFileLocation = $"{directory}\\{filename}_{datestamp}{extension}"; + //Move and set msg. File.Move(fileLocation, newFileLocation); msg = "The previous export has been renamed, the export file has been created. "; }