ImageMerge problem

I am in trouble with mail merging images. There is no problem with images form database. But when I am using the code below the mailmerge causes an "ArgumentException" exception.

DataTable dt2 = new DataTable(); dt2.Columns.Add("Photo1",typeof(System.Byte[]));
dt2.Columns.Add("Photo2",typeof(System.Byte[]));
dt2.TableName = "Photos";
DataRow dr2;
dr2 = dt2.NewRow();
FileStream fs = new FileStream("1.gif",FileMode.Open);
BinaryReader br = new BinaryReader(fs);
dr2["Photo1"] = br.ReadBytes((int)br.BaseStream.Length));
dr2["Photo2"] = br.ReadBytes((int)br.BaseStream.Length));
br = null;
fs.Close();
fs = null;
dt2.Rows.Add(dr2);

document.MailMerge.ExecuteGroup(dt2);

The i have configured merge fields in word document like in your emloyeesreport example.
where is the problem ? cany ou give me an advice about merging an external image form hdd to the merge field (Image:Photo1) of word document template.

Thank you



1 Reply

BP Bhuvaneswari P Syncfusion Team June 4, 2008 04:48 AM UTC

Hi Lokelse,

Thank you for your interest in SYncfusion products.

I am able to reproduce the issue. This is due to the image is not converted to bytes properly. Please refer the below code snippet to do so:

[C#]

FileStream fs = new FileStream(@"..\..\Nature.jpg",FileMode.Open);
byte[] inByte = new byte[fs.Length];
fs.Read(inByte, 0, inByte.Length);
dr2["Photo1"] = inByte;
dr2["Photo2"] = inByte;

Here is the sample for your reference:

http://websamples.syncfusion.com/samples/DocIO.Windows/F74221/main.htm


Please try this and let us know if this helps you.

Best Regards,
Bhuvana


Loader.
Up arrow icon