I was assigned the task of displaying images attached to InfoPath form using file attachment control in one of the SQL Server Reporting Services Report.
For this we need to add an image control and set it’s property in the following manner
Image Source :- Database
Then select appropriate DataSet, Image Field and MimeType
Here to display the Image properly we need to write a Report Assembly with the following code.
/// Takes string value for image from the infopath form
/// and converts it to proper bytes for displaying it as an image
/// <param name="imageData">string representation of the image</param>
/// <returns>corrected byte array</returns>
public static byte GetCorrectedByte(string imageData)
byte attachmentNodeBytes = Convert.FromBase64String(imageData);
// Position 20 contains a DWORD indicating the length of the
// filename buffer. The filename is stored as Unicode so the
// length is multiplied by 2.
int fnLength = attachmentNodeBytes * 2;
// The file is located after the header, which is 24 bytes long
// plus the length of the filename.
byte fileContents = new byte[attachmentNodeBytes.Length - (24 + fnLength)];
for (int i = 0; i < fileContents.Length; ++i)
fileContents[i] = attachmentNodeBytes[24 + fnLength + i];
And set the value for image control as