Add Barcodes

Navigation:  How to Use It in Reporting Services >

Add Barcodes

Previous pageReturn to chapter overviewNext page

Follow the instructions to add the barcodes to the report.

 

1.In order to use the Barcode .NET control in the Reporting Services, please copy MW6.Barcode.dll to "C:\Program Files\Microsoft Visual Studio X\Common7\IDE\PrivateAssemblies" for 32 bit OS or "C:\Program Files (x86)\Microsoft Visual Studio X\Common7\IDE\PrivateAssemblies" for 64 bit OS, the X value is associated with Visual Studio .NET version, it might be 8 for .NET 2005, 9.0 for .NET 2008, 10.0 for .NET 2010, 11.0 for .NET 2012.

 

2.Right click the last column in the table, Select the "Insert Column to the Right".

Insert_Column

3.Change the column title to the "Barcode ID".

Report_1

4.On the "Report" menu, click the "Report Properties", click the "References" tab, click the two-dot button Three_Dots to open the "Add Reference" dialog.

A. Click the "Browse" tab, navigate to the location of the assembly MW6.Barcode.dll, select the file and click the "Add" button.

B. Click the ".NET" tab, highlight the assemblies "System.Drawing" and "System.Windows.Form", click the "Add" button.

C. Enter "MW6.Barcode.BarcodeNet" in the "Class name" box, enter "objBC" in the "Instance name" box to create an assembly object to use in the code to retrieve the barcode image byte stream.

Report_Prop_Ref_1D

5.On the same "Report Properties" dialog, click the "Code" tab, copy and paste the following code into this tab, this function is used to retrieve the barcode image byte stream, modify the code a bit to meet your application requirements.

 

Public Function GetImgStream(ByVal DataStr As String) As Byte()

 

 Dim MS As System.IO.MemoryStream = New System.IO.MemoryStream

 Dim ImgStream As Byte()

 

 Dim ExtraWidth As Integer, ExtraHeight As Integer

 Dim ActualWidth As Integer, ActualHeight As Integer

 

 objBC.Data = DataStr

 objBC.CheckDigit = True

 objBC.CheckDigitToText = True

 objBC.ShowText = True

 objBC.Size = New System.Drawing.Size(408, 104)

 objBC.SupplementGap = 0.5

 objBC.SymbologyType = MW6.Barcode.enumSymbologyType.Code_128

 objBC.TextFont = New System.Drawing.Font("Arial", 12.0!)

 objBC.UPCESystem = MW6.Barcode.enumUPCESystem.ustSystem0

 objBC.Wide2NarrowRatio = 2.0

 

 ' Get the actual barcode width and height (in pixels)

 ' Render the barcode on the computer screen

 objBC.GetActualSize(True, Nothing, ActualWidth, ActualHeight)

 

 ExtraWidth = 20

 ExtraHeight = 60

 

 ' Image size = barcode size + extra space

 objBC.SetSize(ActualWidth + ExtraWidth, ActualHeight + ExtraHeight)

 

 ' Save the barcode image in the memory using the Jpeg format

 objBC.SaveAsMemory(MS, System.Drawing.Imaging.ImageFormat.Jpeg)

 

 ImgStream = MS.ToArray

 

 MS.Close()

 

 Return ImgStream

 

End Function

 

 

Report_Code

6.Change the "BackgroundImage" property of the text box in the "Barcode ID" column to display the barcode image encoding ID value.

A. Source: Select the Database from the drop-down list, since the data will be pulled from a database field.

B. Value: Enter the string "=code.GetImgStream(Fields!ID.Value)", it will ask the report to use the GetImgStream() function to retrieve the barcode image byte stream for the ID field value of the database.

C. MIMEType: Select the image/jpeg from the drop-down list, since the barcode image is in jpeg format.

D. BackgroundRepeat: Select the NoRepeat from the drop-down list, so only one image will be placed in the text box.

Prop_1D_Text

7.Click the "Preview" tab to check the barcode result.

Report_Preview

8.For the reporting services deployment, check out Microsoft Knowledge Base article 842419 with the title "How to grant permissions to a custom assembly that is referenced in a report in Reporting Services", it is required to update the security settings of the .NET Framework to allow the MW6.Barcode.dll assembly to run properly.