/// <summary> /// This thing does the saving. /// </summary> /// <param name="fl">A <see cref="System.Collections.Generic.List<>"/> of destination paths.</param> /// <returns>Returns a <see cref="System.Boolean"/>, indicating success.</returns> private Boolean SaveFiles(List <String> fl) { Int32 saveVersion = (Int32)swSaveAsVersion_e.swSaveAsCurrentVersion; Int32 saveOptions = (Int32)swSaveAsOptions_e.swSaveAsOptions_Silent; Int32 refErrors = 0; Int32 refWarnings = 0; Boolean success = true; string tmpPath = Path.GetTempPath(); ModelDocExtension swModExt = default(ModelDocExtension); ExportPdfData swExportPDFData = default(ExportPdfData); foreach (String fileName in fl) { FileInfo fi = new FileInfo(fileName); string tmpFile = tmpPath + "\\" + fi.Name; if (drawingPath != String.Empty) { swFrame.SetStatusBarText(String.Format("Checking path: '{0}'", fileName)); if (!CreatePath(fileName)) { ExportPDFException e = new ExportPDFException("Unable to save file, folder could not be created."); //e.Data.Add("who", System.Environment.UserName); //e.Data.Add("when", DateTime.Now); throw e; } String[] obj = (string[])swDraw.GetSheetNames(); object[] objs = new object[obj.Length - 1]; DispatchWrapper[] dr = new DispatchWrapper[obj.Length - 1]; for (int i = 0; i < obj.Length - 1; i++) { swDraw.ActivateSheet(obj[i]); Sheet s = (Sheet)swDraw.GetCurrentSheet(); objs[i] = s; dr[i] = new DispatchWrapper(objs[i]); } swFrame.SetStatusBarText(String.Format("Exporting '{0}'", fileName)); bool layerPrint = swApp.GetUserPreferenceToggle((int)swUserPreferenceToggle_e.swPDFExportIncludeLayersNotToPrint); swApp.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swPDFExportIncludeLayersNotToPrint, true); swExportPDFData = swApp.GetExportFileData((int)swExportDataFileType_e.swExportPdfData); swModExt = swModel.Extension; success = swExportPDFData.SetSheets((int)swExportDataSheetsToExport_e.swExportData_ExportAllSheets, (dr)); success = swModExt.SaveAs(tmpFile, saveVersion, saveOptions, swExportPDFData, ref refErrors, ref refWarnings); //success = swModel.SaveAs4(tmpFile, saveVersion, saveOptions, ref refErrors, ref refWarnings); swApp.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swPDFExportIncludeLayersNotToPrint, layerPrint); try { File.Copy(tmpFile, fileName, true); } catch (UnauthorizedAccessException uae) { throw new ExportPDFException( String.Format("You don't have the reqired permission to access '{0}'.", fileName), uae); } catch (ArgumentException ae) { throw new ExportPDFException( String.Format("Either '{0}' or '{1}' is not a proper file name.", tmpFile, fileName), ae); } catch (PathTooLongException ptle) { throw new ExportPDFException( String.Format("Source='{0}'; Dest='{1}' <= One of these is too long.", tmpFile, fileName), ptle); } catch (DirectoryNotFoundException dnfe) { throw new ExportPDFException( String.Format("Source='{0}'; Dest='{1}' <= One of these is invalid.", tmpFile, fileName), dnfe); } catch (FileNotFoundException fnfe) { throw new ExportPDFException( String.Format("Crap! I lost '{0}'!", tmpFile), fnfe); } catch (IOException) { System.Windows.Forms.MessageBox.Show( String.Format("If you have the file, '{0}', selected in an Explorer window, " + "you may have to close it.", fileName), "This file is open somewhere.", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); return(false); } catch (NotSupportedException nse) { throw new ExportPDFException( String.Format("Source='{0}'; Dest='{1}' <= One of these is an invalid format.", tmpFile, fileName), nse); } if (!File.Exists(fileName)) { success = false; } if (success) { swFrame.SetStatusBarText(String.Format("Exported '{0}'", fileName)); if (fileName.StartsWith(Properties.Settings.Default.KPath) && APathSet.WriteToDb) { savedFile = fileName; if (fileName.EndsWith("PDF")) { InsertIntoDb(fileName, Properties.Settings.Default.PDFTable); drwKey = GetKeyCol(fi.Name); } if (fileName.EndsWith(@"EPRT") || fileName.EndsWith("EASM")) { InsertIntoDb(fileName, Properties.Settings.Default.eDrawingTable); } } if ((fileName.StartsWith(Properties.Settings.Default.MetalPath) && fileName.EndsWith("PDF")) && APathSet.WriteToDb) { _metalDrawing = true; InsertIntoDb(fileName, Properties.Settings.Default.metalTable); drwKey = GetKeyCol(fi.Name); } } else { ExportPDFException e = new ExportPDFException(String.Format("Failed to save '{0}'", fileName)); //e.Data.Add("who", System.Environment.UserName); //e.Data.Add("when", DateTime.Now); throw e; } } } if (success) { return(true); } else { return(false); } }