Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I use rdlc report in asp.net using c# to download report in pdf report but pdf report is not download. Pls help.


protected void btnSubmit_Click(object sender, EventArgs e)
{
DataSet ds = new DataSet();
string contentType = string.Empty;
if (ddlFileFormat.SelectedValue.Equals(".pdf"))
contentType = "application/pdf";
DataTable dsData = new DataTable();
dsData = getReportData();
string FileName = "File_" + DateTime.Now.ToString("ddmmyyyyhhmmss") + ddlFileFormat.SelectedValue;
string extension;
string enconding;
string mimetype;
string[] streams;
Warning[] warrings;
LocalReport report = new LocalReport();
report.ReportPath = Server.MapPath("~/rajpolice/AdmitcardPst.rdlc");
ReportDataSource rds = new ReportDataSource();
rds.Name = "DataSetPST";
rds.Value = dsData;
report.DataSources.Add(rds);

// Error details:-
{"An error occurred during local report processing."}
//
// Bug this line //////// Byte[] mybytes = report.Render(ddlFileFormat.SelectedItem.Text, null, out extension, out enconding, out mimetype, out streams, out warrings);
using (FileStream fs = File.Create(Server.MapPath("~/download/") + FileName))
{
fs.Write(mybytes, 0, mybytes.Length);
}
Response.ClearHeaders();
Response.ClearContent();
Response.Buffer = true;
Response.Clear();
Response.ContentType = contentType;
Response.AddHeader("Content-Disposition", "attachment; filename=" + FileName);
Response.WriteFile(Server.MapPath("~/download/" + FileName));
Response.Flush();
Response.Close();
Response.End();

}
private DataTable getReportData()
{
DataSet dsData = new DataSet();
string qry = "select Name from Tbl_PST_DATA where [FORM NO]='" + txtFrmNo.Text + "' and DOB='" + Convert.ToDateTime(txtDateofBirth.Text, System.Globalization.CultureInfo.GetCultureInfo("en-GB")) + "' ";
ClsDa.GetData(qry, dsData);
return dsData.Tables[0];
}
Posted

1 solution

You can use ReportViewer for this like:

C#
private void CreatePDFFromRdlc(string fileName)
{
    Warning[] warnings;
    string[] streamIds;
    string mimeType = string.Empty;
    string encoding = string.Empty;
    string extension = string.Empty;

    // Setup the report viewer object and get the array of bytes
    ReportViewer viewer = new ReportViewer();
    viewer.ProcessingMode = ProcessingMode.Local;
    viewer.LocalReport.ReportPath = "AdmitcardPst.rdlc";

    byte[] bytes = viewer.LocalReport.Render("PDF", null, out mimeType, out encoding, out extension, out streamIds, out warnings);

    // Now that you have all the bytes representing the PDF report, buffer it and send it to the client.
    Response.Buffer = true;
    Response.Clear();
    Response.ContentType = mimeType;
    Response.AddHeader("content-disposition", "attachment; filename=" + fileName + "." + extension);
    Response.BinaryWrite(bytes); // create the file
    Response.Flush();
}


Hope this helps!
 
Share this answer
 
Comments
Member 11675009 12-Oct-15 7:38am    
Problam is not solve, same problam is to be done. If you intersted i want to send any details.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900