public static response CreateZipFromDosar(Models.Dosar dosar, bool bulk) // bulk = false - fisiere grupate pe tip documente / bulk = true - fisiere la gramada { response r = new response(); try { Models.DocumentScanat[] dss = (Models.DocumentScanat[])dosar.GetDocumente().Result; //Models.TipDocument[] tds = (Models.TipDocument[])dosar.GetDocumenteTipuri().Result; string zipFilePath = Path.Combine(CommonFunctions.GetTempFolder(), String.Format("{0}.zip", dosar.NR_DOSAR_CASCO)); using (FileStream zipFile = new FileStream(zipFilePath, FileMode.Create)) { using (ZipArchive archive = new ZipArchive(zipFile, ZipArchiveMode.Create)) { foreach (Models.DocumentScanat ds in dss) { try { if (ds.VIZA_CASCO) { response rg = PdfGenerator.GeneratePdfWithSignatureFromDocument(ds); ZipArchiveEntry entry = null; if (!bulk) { //entry = archive.CreateEntry(String.Format("{0}/{1}", dosar.NR_DOSAR_CASCO, ds.DENUMIRE_FISIER), CompressionLevel.Optimal); // old version - fara semnatura digitala entry = archive.CreateEntry(String.Format("{0}/{1}", dosar.NR_DOSAR_CASCO, rg.Message), CompressionLevel.Optimal); } else { Models.TipDocument td = (Models.TipDocument)ds.GetTipDocument().Result; //entry = archive.CreateEntry(String.Format("{0}/{1}/{2}", dosar.NR_DOSAR_CASCO, td.DENUMIRE, ds.DENUMIRE_FISIER), CompressionLevel.Optimal); // old version - fara semnatura digitala entry = archive.CreateEntry(String.Format("{0}/{1}/{2}", dosar.NR_DOSAR_CASCO, td.DENUMIRE, rg.Message), CompressionLevel.Optimal); } using (BinaryWriter writer = new BinaryWriter(entry.Open())) { /* * ds.GetFileContent(); * writer.Write(ds.FILE_CONTENT); * writer.Flush(); */ byte[] src = File.ReadAllBytes(rg.Result.ToString()); writer.Write(src); writer.Flush(); File.Delete(rg.Result.ToString()); } } }catch (Exception exp) { LogWriter.Log(exp); } } } } return(new response(true, zipFilePath, zipFilePath, null, null)); } catch (Exception exp) { LogWriter.Log(exp); return(new response(false, exp.Message, null, null, new List <Error>() { new Error(exp) })); } }