Click here to Skip to main content
15,895,740 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hai,

This is my code:

C#
DataTable dtDS = ds.Tables["tblDS"];
if (dtDS.Rows.Count != 0)
{
    DataRow dr = dtDS.Rows[0];

    ReportViewer viewer = new ReportViewer();
    viewer.ProcessingMode = ProcessingMode.Local;
    LocalReport lr = viewer.LocalReport;
    lr.ReportPath = ConfigUtil.GetAppSetting("DataSheetType_" + dr["DataSheetType"].ToString());
    ReportDataSource rds = new ReportDataSource();
    rds.Value = ds.Tables[0];
    rds.Name = "report";

    HTMLConverter rtf = new HTMLConverter();

    if (dr["SO1_Address"].ToString() != "")
    {
        dr["SO1_Address"] = rtf.HTML2RTF(dr["SO1_Address"].ToString(), 16);
    }

    lr.DataSources.Add(rds);                        

    string reportType = "PDF";
    string mimeType = "application/pdf";
    string encoding;
    string fileNameExtension = Guid.NewGuid().ToString() + ".pdf";

    string deviceInfo =
    "<DeviceInfo>" +
    "  <OutputFormat>PDF</OutputFormat>" +                        
     "</DeviceInfo>";

    Warning[] warnings;
    string[] streams;
    byte[] renderedBytes;                        

    renderedBytes = lr.Render(
    reportType,
    deviceInfo,
    out mimeType,
    out encoding,
    out fileNameExtension,
    out streams,
    out warnings);

    Response.Clear();
    Response.ContentType = mimeType;
    Response.AddHeader("content-disposition", "attachment; filename=foo." + fileNameExtension);
    Response.BinaryWrite(renderedBytes);
    Response.End();
}


The code compiler returns an exception while trying to execute the lr.Render code. I have no idea what's wrong?

lr.ReportPath is an rdlc report file.
Posted
Comments
Abhinav S 13-Aug-14 11:03am    
What is the error?
Sergey Alexandrovich Kryukov 13-Aug-14 12:13pm    
There is no such concept, "return exception". The whole idea of exception is to work outside of the usual call return (stack-based) mechanism; this is a kind of time machine.
Anyway, in what line? Please, full exception information.
—SA
dannyvkempen 14-Aug-14 3:35am    
((ex.InnerException).InnerException).Message
The report definition is not valid. Details: The report definition has an invalid target namespace 'http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition' which cannot be upgraded.

Here starts the exception

renderedBytes = lr.Render(
reportType,
deviceInfo,
out mimeType,
out encoding,
out fileNameExtension,
out streams,
out warnings);
dannyvkempen 14-Aug-14 3:59am    
Now i have the following code where i try to fill the parameters in the report:
int TotalReportParameters = 1;
ReportParameter[] reportParameters = new ReportParameter[TotalReportParameters];
reportParameters[0] = new ReportParameter("Email", dr["Email"].ToString(), true);

viewer.LocalReport.SetParameters(reportParameters);

I get the following error:
the definition of the report 'Main Report' is invalid

This error is the same error with my previous code above.

1 solution

Use this Link. You can understand the easy way of covert in to number of formats including pdf.

http://www.aspsnippets.com/Articles/Export-DataSet-or-DataTable-to-Word-Excel-PDF-and-CSV-Formats.aspx[^]
 
Share this answer
 

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