public FaxingInformation CreateFax(FaxingInformation faxingInformation) { string temporaryPath = string.Empty; faxingInformation.FaxName = Guid.NewGuid().ToString() + ".pdf"; FaxRepository faxData = new FaxRepository(); string[] firstFaxTo = faxingInformation.FaxTo.Split('~'); List<FaxToInformation> data = new List<FaxToInformation>(); if (faxingInformation.FaxTo.Substring(0, 1) == "G") { data = faxData.GetFaxToInformationGreenway(firstFaxTo[0]); } else { data = faxData.GetFaxToInformation(firstFaxTo[0]); } try { faxingInformation.FaxTo = data[0].Name; } catch { } try { DocumentRepository documentData = new DocumentRepository(); CurrentDocuments faxTodocument = documentData.GetCurrentDocumentPathPdf(Utility.GetUserName()); Logging.LogErrors(ConfigurationValues.ErrorLogPath, faxTodocument.PathToCurrentPdfDocument); MemoryStream newPdfStream = Utility.CreateMemoryStreamFromPdf(faxTodocument.PathToCurrentPdfDocument); temporaryPath = ConfigurationValues.TemporaryFaxPath + Utility.GetUserName() + "\\" + faxingInformation.FaxName; Logging.LogErrors(ConfigurationValues.ErrorLogPath, temporaryPath); FileStream newPdfStreamFile = new FileStream(temporaryPath, FileMode.Create); newPdfStream.WriteTo(newPdfStreamFile); Logging.LogErrors(ConfigurationValues.ErrorLogPath, "writing to file"); newPdfStream.Close(); Logging.LogErrors(ConfigurationValues.ErrorLogPath, "Closing stream"); newPdfStreamFile.Close(); MemoryStream coverSheet = CreateCoverSheetV2(faxingInformation.FaxTo, data[0].FaxNumber, Utility.GetPDFPageCount(newPdfStreamFile.Name), faxingInformation.Notes, faxingInformation.From, int.Parse(faxingInformation.Cover)); faxingInformation.PageCount = Utility.GetPDFPageCount(newPdfStreamFile.Name); faxingInformation.FaxNumber = UpdatedFaxNumber(data[0].FaxNumber); faxingInformation.Name = faxingInformation.FaxTo; FileStream presStream = new FileStream(ConfigurationValues.TemporaryFaxPath + Utility.GetUserName() + "\\cover.pdf", FileMode.Create); coverSheet.WriteTo(presStream); coverSheet.Close(); presStream.Close(); if (faxingInformation.CoverSheetOnly == "T") { File.Copy(ConfigurationValues.TemporaryFaxPath + Utility.GetUserName() + "\\cover.pdf", newPdfStreamFile.Name, true); File.Delete(ConfigurationValues.TemporaryFaxPath + Utility.GetUserName() + "\\cover.pdf"); } else { Utility.MergeTwoPDFDocuments(ConfigurationValues.TemporaryFaxPath + Utility.GetUserName() + "\\cover.pdf", newPdfStreamFile.Name); } faxingInformation.FaxPath = newPdfStreamFile.Name; return faxingInformation; } catch (Exception er) { Logging.LogErrors(ConfigurationValues.ErrorLogPath, er.ToString()); return faxingInformation; } }