protected override void OnExecute(object param) { BSkyMouseBusyHandler.ShowMouseBusy();//ShowProgressbar_old(); IUnityContainer container = LifetimeService.Instance.Container; IDataService service = container.Resolve <IDataService>(); IUIController controller = container.Resolve <IUIController>(); if (controller.GetActiveDocument().isUnprocessed) { NewDatasetProcessor procDS = new NewDatasetProcessor(); bool isProcessed = procDS.ProcessNewDataset("", true); if (isProcessed)//true:empty rows cols removed successfully. False: whole dataset was empty and nothing was removed. { controller.GetActiveDocument().isUnprocessed = false; } else { BSkyMouseBusyHandler.HideMouseBusy(); MessageBox.Show("The dataset is empty. Please populate the dataset and save the file.", "Empty Dataset", MessageBoxButton.OK, MessageBoxImage.Information); return; } } //Get current filetype from loaded dataset. This is file extension and Filter DataSource actds = controller.GetActiveDocument();//06Nov2012 if (actds == null) { return; } string datasetName = "" + actds.Name;//uadatasets$lst$ //string datasetName = "uadatasets$lst$" + controller.GetActiveDocument().Name; //Also try to get the filename of currently loaded file. This is FileName. string extension = controller.GetActiveDocument().Extension; string filename = controller.GetActiveDocument().FileName; SaveFileDialog saveasFileDialog = new SaveFileDialog(); saveasFileDialog.Filter = FileNameFilter; //CheckBox cbox = new CheckBox(); //saveasFileDialog.FileName = filename;////// Window1 appwin = LifetimeService.Instance.Container.Resolve <Window1>(); bool? output = saveasFileDialog.ShowDialog(appwin);//Application.Current.MainWindow); if (output.HasValue && output.Value) { //If the filename provided by user matches to any of the dataset's disk filename, currently open // in the grid then we must not let user overwrite // and inform him/her to first close the dataset whose filename matches and then try Save-As again. // //Only thing that may confuse users is, in the first Microsoft-SaveAs dialog they already decided //to overwrite an existing file (which happens to be loaded in the grid also) but we prompt them //again telling that the file is open in the grid and skip the SaveAs operation with message. // List <string> dsfnames = controller.GetAllOpenDatasetsInGrid(); if (dsfnames.Contains(saveasFileDialog.FileName)) { BSkyMouseBusyHandler.HideMouseBusy(); string fullpathfilename = saveasFileDialog.FileName; string filenameonly = Path.GetFileName(saveasFileDialog.FileName); //The filenameonly dataset (fullpathfilename) is already open in the datagrid. Close the dataset first and then try Save-As again. MessageBox.Show(BSky.GlobalResources.Properties.Resources.The + " \'" + filenameonly + "\' " + BSky.GlobalResources.Properties.Resources.Dtaset + " (" + fullpathfilename + ") " + BSky.GlobalResources.Properties.Resources.OverwritingOpenDatasetNotallowed, BSky.GlobalResources.Properties.Resources.SaveAsFailed, MessageBoxButton.OK, MessageBoxImage.Asterisk); return; } service.SaveAs(saveasFileDialog.FileName, controller.GetActiveDocument()); // #0 controller.GetActiveDocument().Changed = false; //21Mar2014 during close it should not prompt again for saving if (saveasFileDialog.FileName.ToLower().EndsWith("sav")) //12Feb2018 we dont want to open SaveAs-ed SAV files. { MessageBox.Show(BSky.GlobalResources.Properties.Resources.SaveAsSucces + saveasFileDialog.FileName, BSky.GlobalResources.Properties.Resources.Saved, MessageBoxButton.OK, MessageBoxImage.Asterisk); } else if (System.IO.File.Exists(saveasFileDialog.FileName)) { //Close current Dataset on whic Save As was run FileCloseCommand fcc = new FileCloseCommand(); fcc.CloseDataset(false); //Open Dataset that was SaveAs-ed. FileOpenCommand fo = new FileOpenCommand(); fo.FileOpen(saveasFileDialog.FileName, true); } else { BSkyMouseBusyHandler.HideMouseBusy();//HideProgressbar_old(); MessageBox.Show(BSky.GlobalResources.Properties.Resources.SaveAsFailed + saveasFileDialog.FileName, BSky.GlobalResources.Properties.Resources.InternalError, MessageBoxButton.OK, MessageBoxImage.Asterisk); } } BSkyMouseBusyHandler.HideMouseBusy();//HideProgressbar_old(); }