PROBLEMA : Cual es el código fuente para hacer dicha exportación ?
SOLUCION : Debe haber creado previamente su Informe .rdlc. Para este ejemplo vamos a asumir que tiene el informe Report1.rdlc cuya origen de datos es una lista de objetos sencillos. El siguiente es el código fuente escrito en C# que exporta el reporte a la ruta : D:\auxil\reporte1.pdf.
Este código fuente puede ajustarse para exportar cualquier informe .rdlc
private void CreateReportPdf()
{
//Origen de Datos que pobla el Reporte, en este caso es una lista de objetos sencillos, pero puede ser un Dataset o un DataTable
List<CItem2> list1 = new List<CItem2>{
new CItem2{ Id= 1, Description ="Amarillo"},
new CItem2{ Id= 2, Description ="Azul"},
new CItem2{ Id= 3, Description ="Rojo"},
};
try
{
//1. Cargar fisicamente el reporte
.rdlc
LocalReport report = new LocalReport();
report.ReportPath = Server.MapPath("~/Report1.rdlc");
//2. Establecer el Origen de datos.
ReportDataSource rds = new ReportDataSource();
rds.Name = "DataSet1"; //Este es el nombre del DataSet que estableció en tiempo de Diseño al .rdlc
rds.Value = list1; //Origen de datos : DataTable, List, etc.
report.DataSources.Add(rds);
//3. Establecer la ruta Destino donde se va a Guardar el .pdf generado
string pathFilePdf = @"D:\auxil\reporte1.pdf";
//4. Escoja cualquier formato al que quiera Exportar su reporte.
//Byte[]
mybytes = report.Render("Excel");
//Byte[] mybytes =
report.Render("WORD");
Byte[] mybytes = report.Render("PDF"); //for exporting to PDF
using (FileStream fs = File.Create(pathFilePdf)) //Report1.doc
{
fs.Write(mybytes, 0,
mybytes.Length); //Exportar el Reporte
}
}
catch (Exception ex)
{
Console.writeline(ex);
}
}
No hay comentarios.:
Publicar un comentario