This is a migrated thread and some comments may be shown as answers.

Out of Memory Exception

1 Answer 161 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Jon
Top achievements
Rank 1
Jon asked on 15 Apr 2012, 09:18 PM
Hi.. I have the following code with is throwing an out of memory exception.
The report returns just 300 records.. (12 fields)   and only 10 records 'hit' this code to load an image.
Any ideas? 

   private void pictureBox1_ItemDataBinding(object sender, EventArgs e)
        {
           Telerik.Reporting.Processing.ReportItemBase itemBase = (Telerik.Reporting.Processing.ReportItemBase)sender;
           string file = itemBase.DataObject["PHOTO_filename"] as string;




           if (!String.IsNullOrEmpty(file) && File.Exists("S:\\Conference\\photos_noncrm\\" + file))
           {
               Image image1 = Image.FromFile(@"S:\\Conference\\photos_noncrm\\" + file);


               this.pictureBox1.Value = image1;
           }
           else
           {


               this.pictureBox1.Value = "=Fields.PHOTO";


           }
        }

1 Answer, 1 is accepted

Sort by
0
Petio Petkov
Telerik team
answered on 17 Apr 2012, 03:47 PM
Hello Jon,

When you're in the context of events you should use the processing object and not the definition(more info on definition vs. processing is available in Understanding Events help article).
Set the PictureBox1's Value property to =Fields.PHOTO in the definition and modify the event handler to:

private void pictureBox1_ItemDataBinding(object sender, EventArgs e)
      {
         Telerik.Reporting.Processing.PictureBox itemBase = (Telerik.Reporting.Processing.PictureBox)sender;
         string file = itemBase.DataObject["PHOTO_filename"] as string;
 
 
         if (!String.IsNullOrEmpty(file) && File.Exists("S:\\Conference\\photos_noncrm\\" + file))
         {
             Image image1 = Image.FromFile(@"S:\\Conference\\photos_noncrm\\" + file);
             itemBase.Image = image1;
         }
      }

Still the code should not be the reason for the exception you've received. Rather we suspect that your images are large in size and when they are uncompressed in memory in order to be shown in the report, they occupy considerable amount of memory and can cause out of memory exceptions. The resolution of the images plays role as well, when it comes to how many pages would be generated.
Greetings,
Petio Petkov
the Telerik team
NEW in Q1'12: Telerik Report Designer (Beta) for ad-hoc report creation. Download as part of Telerik Reporting Q1 2012. For questions and feedback, use the new Telerik Report Designer Forum.
Tags
General Discussions
Asked by
Jon
Top achievements
Rank 1
Answers by
Petio Petkov
Telerik team
Share this question
or