Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi all,

I have trouble using StringReader to load my RDLC file after modifying it seems like no effect.

If I overwrite the original RDCL file it works

Please correct this code...

C#
public void localizeReport(LocalReport report)
        {
            //used to call the resources from database
            DbResourceManager resourceManager=new DbResourceManager("ReportTextBox");
            
            //access the report xml file
            XmlDocument xml = new XmlDocument();
            xml.Load(report.ReportPath);
            XmlNamespaceManager nsmgr = new XmlNamespaceManager(xml.NameTable);
            nsmgr.AddNamespace("nm", "http://schemas.microsoft.com/" +
                               "sqlserver/reporting/2005/01/reportdefinition");
            nsmgr.AddNamespace("rd", "http://schemas.microsoft.com/" +
                               "SQLServer/reporting/reportdesigner");

foreach (string nodeName in new string[]{"Value"})
            {
                foreach (XmlNode node in xml.DocumentElement.SelectNodes(String.Format("//nm:{0}[@rd:LocID]", nodeName), nsmgr))
                {
                    String nodeValue = node.InnerText.Replace(" :","");
                    if (String.IsNullOrEmpty(nodeValue) || !nodeValue.StartsWith("="))
                    {
                        try
                        {
                            string localizedValue = resourceManager.GetString(nodeValue.ToString());
                            if (!String.IsNullOrEmpty(localizedValue))
                            {
                                if (node.InnerText == "Booking Confirmation")
                                {
                                    node.InnerText = localizedValue.ToString();
                                }
                                else
                                {
                                    node.InnerText = localizedValue.ToString() + " :";
                                }
                            }
                        }

                        catch (Exception ex)
                        {
                            throw new Exception(ex.ToString());
                        }

                    }
                }

            }
//xml.save(report.ReportPath);  - it will overwrite the original report not good idea.
using (StringReader rdlcSR = new StringReader(xml.DocumentElement.OuterXml))
            {
                report.LoadReportDefinition(rdlcSR); //unable to load the report what to do??
}
}


C#
private void btnPreview_Click(object sender, EventArgs e)
{
    reportViewer1.LocalReport.ReportPath = "C:/FM80/TR_BookUI/Report/RptBookingConfirmation.rdlc";

    localizeReport(reportViewer1.LocalReport);
    if (cboStartCustCode.Text == "")
    {
        this.dtbRptBookingConfirmationTableAdapter.Fill(this.dstRptBookingConfirmation.dtbRptBookingConfirmation, cboStartCustCode.Items[0].ToString(), cboEndCustCode.Items[cboEndCustCode.Items.Count - 1].ToString(), startDate, endDate);
        if (dstRptBookingConfirmation.Tables[0].Rows.Count != 0)
        {
            MessageBox.Show(ResReports.ErrorNoBookingConfirmation, "Message");
        }
    }
    else
    {
        this.dtbRptBookingConfirmationTableAdapter.Fill(this.dstRptBookingConfirmation.dtbRptBookingConfirmation, cboStartCustCode.Text, cboEndCustCode.Text, startDate, endDate);
        if (dstRptBookingConfirmation.Tables[0].Rows.Count <= 0)
            MessageBox.Show(ResReports.ErrorNoBookingConfirmation, "Message");
    }
    this.tPT_SPECIAL_DATA_TblTableAdapter.Fill(this.dstTransportSpecialData.TPT_SPECIAL_DATA_Tbl);
    this.dtbSpecialDataTableAdapter.Fill(this.dstSpecialData.DtbSpecialData);

    reportViewer1.RefreshReport();
}
Posted
Updated 3-Jan-11 15:39pm
v3

Save the original in some temp folder. Modify this copy as per your need and then use it for display. This way your original copy will be left intact and yet you would be able to overwrite and view the modified version when required.
 
Share this answer
 
Comments
Dalek Dave 4-Jan-11 4:13am    
Sage Advice.
hi,

Thanks for the answer.

Can u set an example to load or display the modified RDLC in reportviewer dynamically.
 
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