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.
{
/// <summary>
/// Takes string value for image from the infopath form
/// and converts it to proper bytes for displaying it as an image
/// </summary>
/// <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[20] * 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];
}
return fileContents;
}
}
And set the value for image control as
=(Namespace).FileDecoder.GetCorrectedByte(Fields!fieldName.Value)
Bye..
What tool are you using to create a Report Assembly? I created a new Class Project in Visual Studio 2010, but am not exactly sure how to reference it. I’m guessing I need to deploy it to the GAC on the machine running the report/infopath.
LikeLike