UPDATED April 2nd 2009: Several people have reported to me that the first solution I posted for “How to use the Picture stored in Company Information table:” did not work for them. So I have now updated the section on how to use the picture stored in the Company Information table. The picture is now added in a slightly different way.
There are several ways to do this. Either you use the existing Picture which is stored in table 79 Company Information or you can embed the image into the Report itself, or you can link to the picture externally. In this scenario I will be looking at how to use the picture already in the database and and how to embed the picture into the report itself.
How to embed the Picture:
1. For us to be able to embed the picture into a report we need to have the Company Picture as a file. I have exported the company picture to c:\temp\CompanyPicture.bmp
2. Ok, now let us add this to Report 111. Design Report 111
3. Select "View/Layout" to go into Visual Studio.
4. Select the Report and choose "Report/Embedded Images"
5. Select "New Image..." and select your company picture, in my case c:\temp\CompanyPicture.bmp
6. With that completed open the Toolbox and add a Image control to the Report.
7. With the Image Control added we need to the set correct properties for this control. Set Source=Embedded, Value=companypicutre and MIMEType=image/bmp
9. Save and import RDLC changes, and then compile report in Classic client.
10. Run "dynamicsnav:////runreport?report=111" to open up report 111. And as you can see below company picture is displayed.
We have no looked at how to embed the Company Picture into the report. Now let us have a look on how to use the Company Picture already in the database.
How to use the Picture stored in Company Information table:
1. Deleted the above embedded Company Picture, if you followed the steps above.
2. Design report 111
3. Now we need to have a Variable with is references to the Company Information Table. Lets create a new called CompanyInfo
4. Exit C/AL Globals and ad the following code to the "OnPreReport()" trigger: CompanyInfo.CALCFIELDS(Picture);
5. Now we should add a Picture Box on the Sections with SourceExpr: CompanyInfo.Picture. We need to do this to have the element available for us in Visual Studio.
6. It is now time to open Visual Studio. Select "View/Layout"
7. Notice that we now have an new entry in the DataSet
8. Now lets add this to the report. We need to add the Company Picture first as a TextBox to the body of the report. This will enable us to use it in the Page Header. We add this TextBox in top of the Body.
9. We give the TextBox the following properties:
Value: “=Convert.ToBase64String(Fields!CompanyInfo_Picture.Value)” Name: “CompanyPicture” Visibility Hidden: “True” Color: “Red”
10. Now add the following code to the Report properties.
Shared PictureData as Object
Public Function GetPicture() as Object Return PictureData End Function
Public Function SetPicture(NewData as Object) if NewData>"" PictureData = NewData end if End Function
11. Now let us add the Image control just as we did for the embedded scenario. Open the Toolbox and add a Image control to the Report.
12. With the Image Control added we need to the set correct properties for this control.
Value: “=Convert.FromBase64String(Code.GetPicture())” Source: “Database” MIMEType: “image/bmp”
13. Add textbox to Page Header. Note! This textbox has to be placed above the Picture control just added
Value: “=Code.SetPicture(ReportItems!CompanyPicture.Value)” Visibility Hidden: “True” Color: “Red
14. Save and import RDLC changes, and then compile report in Classic client.
15. Run "dynamicsnav:////runreport?report=111" to open up report 111. And as you can see below company picture is displayed.
Claus Lundstrøm, Program Manager, Microsoft Dynamics NAV
Whenever I try to run example 2 then I'm loosing the connection to the NAV server. Does this work differently in NAV 2009 SP1? Or what might I be doing wrong?
@Erik: it is probably because the textbox with convert.tobase64 string is NOT set as hidden.
i noticed a similar behaviour in one report of mine, too
Thank you for this. It helps a lot.
I've follow the guidance above, inserting image by use the picture store in company information table, but my company logo still unable to show. What's the problem? :S
This is a link a share a lot with others because it saves my time to explain it myself - thanks ;-)
Its not working.
The Image shows a X.
It works for the company picture which never change. Let's say I want to display a company division picture, It works for a single report but as soon I try to generate a report batch from mixed divisions, the picture going on report 2 is on report 3, 3 on 4, 4 on 5... Sound familiar to someone?