Crystal report dynamically load an image on report document
-
Hi I have a crystal report invoicing application that generates invoices. i have a logo on that invoice. I wanted to change the image based on if some condition met on code behind. Can anyone please shed some light on how to do this. This is what i am doing currently. private void CreateImageDataTableAndWriteSchema() { this.DsImages = new DataSet(); DataTable ImageTable = new DataTable("Images"); ImageTable.Columns.Add(new DataColumn("path", typeof(string))); ImageTable.Columns.Add(new DataColumn("image", typeof(System.Byte[]))); this.DsImages.Tables.Add(ImageTable); //this.DsImages.WriteXmlSchema(@"c:\myinvoices\ImagesSchema.xsd"); } as you can see from commented code that, I am creating an xsd dataset and I have added that dataset to the database fields. Then i have place image field from that table on to the report document. Then below i am loading an image file in that dataset/datatable. then i am loading image in to the dataset created above private void LoadLogoImage() { FileStream FilStr = new FileStream("C:\\mystuff\\Images\\my_logo.jpg", FileMode.Open); BinaryReader BinRed = new BinaryReader(FilStr); DataRow dr = this.DsImages.Tables["Images"].NewRow(); dr["path"] = "C:\\mystuff\\Images\\my_logo.jpg"; dr["image"] = BinRed.ReadBytes((int)BinRed.BaseStream.Length); this.DsImages.Tables["Images"].Rows.Add(dr); FilStr.Close(); BinRed.Close(); } Lastly, i am setting the datasource of the report document as following reportDocument.Subreports[SummaryDocument].Database.Tables["Images"].SetDataSource(DsImages.Tables["Images"]); I get error, invalid index when i try to execute this line. As stated above, i am trying to set the Images table datasource to the dataset we just poppulated with image path and byte data. fyi: i have a master report which holds 8 subreport. The SummaryDocument listed above is one of those subreport.
Thanks Needy