Question

I've got a report where I want to use external images to show depending on a service group. There are 3 service groups and each has it's own header (the headers will change accordingly)... The problem is, I'm getting an error of:

An error occurred during local report processing.

Report 'CustQuote' contains external images. The EnableExternalImages property has not been set for this report.

I have set the property to true in both code and on the reportviewer, but still getting the error....

Here is what I've done to load the image in code:

    private void PopulateImage()
    {
        try
        {
            cn = new SqlConnection(GetConnectionString());
            SqlCommand myCmd = new SqlCommand("SELECT * FROM [Chargeables_CustQuote] WHERE ID = 8", cn);

            cn.Open();
            SqlDataReader myReader = myCmd.ExecuteReader();

            if (myReader.HasRows)
            {
                    while (myReader.Read())
                    {

                        string serv = myReader["ServiceGroup"].ToString();
                        if (myReader["ServiceGroup"].ToString() == "BCX")
                        {
                            ReportParameter paramLogo = new ReportParameter();
                            paramLogo.Name = "Path";
                            paramLogo.Values.Add(Server.MapPath("~\\Images\\SOSLetterhead.png"));

                            rtpViewer.LocalReport.SetParameters(paramLogo);
                            rtpViewer.LocalReport.EnableExternalImages = true;
                            rtpViewer.LocalReport.Refresh();                              
                        }
                    }
            }
            cn.Close();
            myReader.Close();

        }
        catch (System.Data.SqlClient.SqlException ex)
        {
            string msg = "Select Error:";
            msg += ex.Message;
            throw new Exception(msg);
        }
    }

     protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            runRptViewer();
            PopulateImage();

        }
    }

This is what my reportviewer looks like:

        <div>
<rsweb:ReportViewer ID="rtpViewer" runat="server" Font-Names="Verdana" Font-Size="8pt" WaitMessageFont-Names="Verdana" WaitMessageFont-Size="14pt" Width="952px" Height="807px"

EnableExternalImages="True">

          <asp:ObjectDataSource ID="ObjectDataSource3" runat="server" SelectMethod="GetData" TypeName="SOSDataSetTableAdapters.VCustomerbaseTableAdapter"></asp:ObjectDataSource>
         <asp:ObjectDataSource ID="ObjectDataSource2" runat="server" SelectMethod="GetData" TypeName="SOSDataSetTableAdapters.Chargeables_ItemsTableAdapter"></asp:ObjectDataSource>
         <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetData" TypeName="SOSDataSetTableAdapters.Chargeables_CustQuoteTableAdapter"></asp:ObjectDataSource>

</div>

For the image property on the rdlc report, source has been set to External, the Value has been set to =Parameters!Path.Value (which is a parameter I created). The parameter has been made with a DataType of Text and the name is Path...

Was it helpful?

Solution

SetParameters takes a ReportParameterCollection not just a ReportParameter.

It should be something like this (untested):

ReportParameterCollection params = new ReportParameterCollection();
params.Add(new ReportParameter("Path", Server.MapPath("~\\Images\\SOSLetterhead.png")));
rtpViewer.LocalReport.SetParameters(params);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top