public void ConvertUsingExcelLibrary(string path) { if (excelFormats.Contains(Path.GetExtension(path))) { ExcelToCsv(path); } else { string newPath = string.Join(".", path.Split(".").SkipLast(1).Append("csv")); CloudBlobClient client = conn.storageAccount.CreateCloudBlobClient(); CloudBlobContainer container = client.GetContainerReference(conn.config.Container); Task checkExists = container.CreateIfNotExistsAsync(); checkExists.Wait(); CloudBlockBlob blob = container.GetBlockBlobReference(path); CloudBlockBlob newBlob = container.GetBlockBlobReference(newPath); blob.Properties.ContentType = "application/json"; newBlob.Properties.ContentType = "application/json"; Stream myBlob = blob.OpenReadAsync().Result; var dataBytes = StreamExtensions.ReadToEnd(myBlob); using (Stream stream = new MemoryStream(dataBytes, 0, dataBytes.Length)) { Task t = newBlob.UploadFromStreamAsync(stream); t.Wait(); } } }
public JsonResult GenerarPlanillaPago(HashSet <int> ids) { var fechaVencimiento = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month)); var modelReport = _db.DeclaracionDeudaCuota.Include(x => x.DeclaracionPrevia).Include(x => x.DeclaracionPrevia.Cliente.Persona).Include(x => x.DeclaracionPrevia.Cliente.Persona.TipoDocumento) .GroupBy(x => new { x.DeclaracionPrevia.PersonaId, x.DeclaracionPrevia.Cliente.Persona.NombreCompleto, NoIdentificacionCompleto = x.DeclaracionPrevia.Cliente.Persona.TipoDocumento.Descripcion + " - " + x.DeclaracionPrevia.Cliente.Persona.NoIdentificacion }) .Select(y => new DeclaracionDeudaCuotaModel { PersonaId = y.Key.PersonaId, NombreCompleto = y.Key.NombreCompleto, NoIdentificacionCompleto = y.Key.NoIdentificacionCompleto, FechaVencimiento = fechaVencimiento, TotalImpuestoIndustriaComercio = y.Sum(x => x.TotalImpuestoIndustriaComercio), ImpuestoAvisosTableros = y.Sum(x => x.ImpuestoAvisosTableros), PagoUnidadesComerciales = y.Sum(x => x.PagoUnidadesComerciales), SobretasaBomberil = y.Sum(x => x.SobretasaBomberil), SobretasaSeguridad = y.Sum(x => x.SobretasaSeguridad), TotalImpuestoCargo = y.Sum(x => x.TotalImpuestoCargo), ValorExoneracionImpuesto = y.Sum(x => x.ValorExoneracionImpuesto), RetencionesDelMunicipio = y.Sum(x => x.RetencionesDelMunicipio), AutoretencionesDelMunicipio = y.Sum(x => x.AutoretencionesDelMunicipio), AnticipoAnioAnterior = y.Sum(x => x.AnticipoAnioAnterior), AnticipoAnioSiguiente = y.Sum(x => x.AnticipoAnioSiguiente), ValorSancion = y.Sum(x => x.ValorSancion), SaldoFavorPeriodoAnterior = y.Sum(x => x.SaldoFavorPeriodoAnterior), TotalSaldoCargo = y.Sum(x => x.TotalSaldoCargo), TotalSaldoFavor = y.Sum(x => x.TotalSaldoFavor), InteresesMora = 0, }).FirstOrDefault(); ReportDocument report = new CRDeclaracionDeudaCuota(); report.Database.Tables[0].SetDataSource(new List <DeclaracionDeudaCuotaModel> { modelReport }); Response.Buffer = false; Response.ClearContent(); Response.ClearHeaders(); var stream = report.ExportToStream(ExportFormatType.PortableDocFormat); // report.ExportToDisk(ExportFormatType.PortableDocFormat, $@"C:\Users\henry\Documents\PlanillaDePago_{DateTime.Now.ToString("yyyyMMddHHmmss")}.pdf"); stream.Seek(0, SeekOrigin.Begin); byte[] m_Bytes = StreamExtensions.ReadToEnd(stream); return(Json(Convert.ToBase64String(m_Bytes, 0, m_Bytes.Length))); // return Json(new { file = File(stream, "application/pdf", $"PlanillaDePago_{DateTime.Now.ToString("yyyyMMddHHmmss")}.pdf") }); }