Free Support Forum - aspose.com

Unable to load GIF image

Hi,

I am using image merge field to load specified image in word document using aspose.words.document. It is working fine for JPG and BMP image but for GIF image following error is dipslayed.

"Cannot load image from field 'HEADER'. The field contains data in unsupported format. Invalid parameter used"

where HEADER is image merge field name i.e IMAGE:HEADER.

follwing is my C# code to load image in word document .

Document doc = new Document(@"c:\Employees.doc");

// Employee.doc contains merge field with name IMAGE:HEADER

DataTable dt = new DataTable();

dt.Columns.Add("HEADER",Type.GetType("System.Byte[]"));

DataRow dr = dt.NewRow();

FileStream file = File.OpenRead(@"D:\header.gif"); // For header.jpg and header.bmp it is working

byte[] buffer = new byte[file.Length];

file.Read(buffer, 0,buffer.Length -1);

dr[0] = buffer;

dt.Rows.Add(dr);

doc.MailMerge.Execute(dt);

file.Close();

doc.Save("image", SaveFormat.FormatDocument , SaveType.OpenInBrowser , Response);

Please let me know i am doing something wrong or there is another method to load image file.

thanks in advance

Susheel Patidar

I think you should use

file.Read(buffer, 0, buffer.Length);

instead of

file.Read(buffer, 0, buffer.Length - 1);

Best regards,