Neodynamic Barcode Professional 3.0 (or greater) for ASP.NET (WebControl)
Microsoft .NET Framework 2.0 (or greater)
Microsoft Visual Studio 2005 or Visual Web Developer 2005 Express Edition. NOTE: For VWD Express Edition, installing the free add-in for ReportViewer is mandatory.
Microsoft SQL Server 2005 (any version) with AdventureWorks Database sample installed
In the following Step-By-Step Guide we're going to create a local report (RDLC file) which features barcoding capabilities by using Barcode Professional for ASP.NET.
Follow these steps:
Follow these steps:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'Fill the datasource from DB
Dim ta As New AdventureWorksTableAdapters.vProductAndDescriptionTableAdapter()
Dim dt As New AdventureWorks.vProductAndDescriptionDataTable()
ta.Fill(dt)
'Create an instance of Barcode Professional
Dim bcp As New Neodynamic.WebControls.BarcodeProfessional.BarcodeProfessional()
'Barcode settings
bcp.Symbology = Neodynamic.WebControls.BarcodeProfessional.Symbology.Code128
bcp.BarHeight = 0.25F
'Update DataTable with barcode image
Dim row As AdventureWorks.vProductAndDescriptionRow
For Each row In dt.Rows
'Set the value to encode
bcp.Code = row.ProductID.ToString()
'Generate the barcode image and store it into the Barcode Column
row.Barcode = bcp.GetBarcodeImage(System.Drawing.Imaging.ImageFormat.Png)
Next
'Create Report Data Source
Dim rptDataSource As New Microsoft.Reporting.WebForms.ReportDataSource("AdventureWorks_vProductAndDescription", dt)
Me.ReportViewer1.LocalReport.DataSources.Add(rptDataSource)
Me.ReportViewer1.LocalReport.ReportPath = Server.MapPath("BarcodeReport.rdlc")
Me.ReportViewer1.LocalReport.Refresh()
End Sub
protected void Page_Load(object sender, EventArgs e)
{
//Fill the datasource from DB
AdventureWorksTableAdapters.vProductAndDescriptionTableAdapter ta = new AdventureWorksTableAdapters.vProductAndDescriptionTableAdapter();
AdventureWorks.vProductAndDescriptionDataTable dt = new AdventureWorks.vProductAndDescriptionDataTable();
ta.Fill(dt);
//Create an instance of Barcode Professional
Neodynamic.WebControls.BarcodeProfessional.BarcodeProfessional bcp = new Neodynamic.WebControls.BarcodeProfessional.BarcodeProfessional();
//Barcode settings
bcp.Symbology = Neodynamic.WebControls.BarcodeProfessional.Symbology.Code128;
bcp.BarHeight = 0.25f;
//Update DataTable with barcode image
foreach (AdventureWorks.vProductAndDescriptionRow row in dt.Rows)
{
//Set the value to encode
bcp.Code = row.ProductID.ToString();
//Generate the barcode image and store it into the Barcode Column
row.Barcode = bcp.GetBarcodeImage(System.Drawing.Imaging.ImageFormat.Png);
}
//Create Report Data Source
Microsoft.Reporting.WebForms.ReportDataSource rptDataSource = new Microsoft.Reporting.WebForms.ReportDataSource("AdventureWorks_vProductAndDescription", dt);
this.ReportViewer1.LocalReport.DataSources.Add(rptDataSource);
this.ReportViewer1.LocalReport.ReportPath = Server.MapPath("BarcodeReport.rdlc");
this.ReportViewer1.LocalReport.Refresh();
}
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Button1.Click
'Fill the datasource from DB
Dim ta As New AdventureWorksTableAdapters.vProductAndDescriptionTableAdapter()
Dim dt As New AdventureWorks.vProductAndDescriptionDataTable()
ta.Fill(dt)
'Create an instance of Barcode Professional
Dim bcp As New Neodynamic.WebControls.BarcodeProfessional.BarcodeProfessional()
'Barcode settings
bcp.Symbology = Neodynamic.WebControls.BarcodeProfessional.Symbology.Code128
bcp.BarHeight = 0.25F
'Update DataTable with barcode image
Dim row As AdventureWorks.vProductAndDescriptionRow
For Each row In dt.Rows
'Set the value to encode
bcp.Code = row.ProductID.ToString()
'Generate the barcode image and store it into the Barcode Column
row.Barcode = bcp.GetBarcodeImage(System.Drawing.Imaging.ImageFormat.Png)
Next
'Create ReportViewer
Dim viewer As New Microsoft.Reporting.WebForms.ReportViewer()
'Create Report Data Source
Dim rptDataSource As New Microsoft.Reporting.WebForms.ReportDataSource("AdventureWorks_vProductAndDescription", dt)
viewer.LocalReport.DataSources.Add(rptDataSource)
viewer.LocalReport.ReportPath = Server.MapPath("BarcodeReport.rdlc")
'Export to PDF
Dim pdfContent As Byte() = viewer.LocalReport.Render("PDF", Nothing, Nothing, Nothing, Nothing, Nothing, Nothing)
'Return PDF
Me.Response.Clear()
Me.Response.ContentType = "application/pdf"
Me.Response.AddHeader("Content-disposition", "attachment; filename=BarcodeReport.pdf")
Me.Response.BinaryWrite(pdfContent)
Me.Response.End()
End Sub
protected void button1_Click(object sender, EventArgs e)
{
//Fill the datasource from DB
AdventureWorksTableAdapters.vProductAndDescriptionTableAdapter ta = new AdventureWorksTableAdapters.vProductAndDescriptionTableAdapter();
AdventureWorks.vProductAndDescriptionDataTable dt = new AdventureWorks.vProductAndDescriptionDataTable();
ta.Fill(dt);
//Create an instance of Barcode Professional
Neodynamic.WebControls.BarcodeProfessional.BarcodeProfessional bcp = new Neodynamic.WebControls.BarcodeProfessional.BarcodeProfessional();
//Barcode settings
bcp.Symbology = Neodynamic.WebControls.BarcodeProfessional.Symbology.Code128;
bcp.BarHeight = 0.25f;
//Update DataTable with barcode image
foreach (AdventureWorks.vProductAndDescriptionRow row in dt.Rows)
{
//Set the value to encode
bcp.Code = row.ProductID.ToString();
//Generate the barcode image and store it into the Barcode Column
row.Barcode = bcp.GetBarcodeImage(System.Drawing.Imaging.ImageFormat.Png);
}
//Create ReportViewer
Microsoft.Reporting.WebForms.ReportViewer viewer = new Microsoft.Reporting.WebForms.ReportViewer();
//Create Report Data Source
Microsoft.Reporting.WebForms.ReportDataSource rptDataSource = new Microsoft.Reporting.WebForms.ReportDataSource("AdventureWorks_vProductAndDescription", dt);
viewer.LocalReport.DataSources.Add(rptDataSource);
viewer.LocalReport.ReportPath = Server.MapPath("BarcodeReport.rdlc");
//Export to PDF
string mimeType;
string encoding;
string fileNameExtension;
string[] streams;
Microsoft.Reporting.WebForms.Warning[] warnings;
byte[] pdfContent = viewer.LocalReport.Render("PDF", null, out mimeType, out encoding, out fileNameExtension, out streams, out warnings);
//Return PDF
this.Response.Clear();
this.Response.ContentType = "application/pdf";
this.Response.AddHeader("Content-disposition", "attachment; filename=BarcodeReport.pdf");
this.Response.BinaryWrite(pdfContent);
this.Response.End();
You can design local reports (RDLC) based on business objects defined in your application. In this scenario, an object data source is simply a collection of arbitrary objects. In this guide, we'll define a custom object with barcoding support that will be used as data source for our report.
Follow these steps:
Public Class Product
Dim m_id As String
Dim m_name As String
Dim m_barcode As Byte()
Public Sub New(ByVal id As String, ByVal name As String, ByVal barcode As Byte())
m_id = id
m_name = name
m_barcode = barcode
End Sub
Public Property Id() As String
Get
Return m_id
End Get
Set(ByVal value As String)
m_id = value
End Set
End Property
Public Property Name() As String
Get
Return m_name
End Get
Set(ByVal value As String)
m_name = value
End Set
End Property
Public Property Barcode() As Byte()
Get
Return m_barcode
End Get
Set(ByVal value As Byte())
m_barcode = value
End Set
End Property
End Class
public class Product
{
string m_id;
string m_name;
byte[] m_barcode;
public Product(string id, string name, byte[] barcode)
{
m_id = id;
m_name = name;
m_barcode = barcode;
}
public string Id
{
get
{
return m_id;
}
set
{
m_id = value;
}
}
public string Name
{
get
{
return m_name;
}
set
{
m_name = value;
}
}
public byte[] Barcode
{
get
{
return m_barcode;
}
set
{
m_barcode = value;
}
}
}
Public Class Catalog
Dim m_products As System.Collections.Generic.List(Of Product)
Public Sub New()
m_products = New System.Collections.Generic.List(Of Product)
End Sub
Public Sub AddProduct(ByVal product As Product)
m_products.Add(product)
End Sub
Public Function GetProducts() As System.Collections.Generic.List(Of Product)
Return m_products
End Function
End Class
public class Catalog
{
private System.Collections.Generic.List m_products;
public Catalog()
{
m_products = new System.Collections.Generic.List();
}
public void AddProduct(Product product)
{
m_products.Add(product);
}
public System.Collections.Generic.List GetProducts()
{
return m_products;
}
}
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'Create an instance of Barcode Professional
Dim bcp As New Neodynamic.WebControls.BarcodeProfessional.BarcodeProfessional()
'Barcode settings
bcp.Symbology = Neodynamic.WebControls.BarcodeProfessional.Symbology.Code128
bcp.BarHeight = 0.25F
'Fill the object datasource.
'NOTE: You may connect to a SQL Server Database and create Product objects based on data returned from such source.
Dim data As New Catalog()
'Create random product info
Dim prodId As String
Dim prodName As String
Dim prodBarcode As Byte()
Dim i As Integer
For i = 1 To 10
'Random product info
prodId = Guid.NewGuid().ToString().Substring(0, 10)
prodName = "Product " + prodId
'Set the value to encode
bcp.Code = prodId
'Generate the barcode image and store it into the Barcode Column
prodBarcode = bcp.GetBarcodeImage(System.Drawing.Imaging.ImageFormat.Png)
'Add new product
data.AddProduct(New Product(prodId, prodName, prodBarcode))
Next
'Create Report Data Source
Dim rptDataSource As New Microsoft.Reporting.WebForms.ReportDataSource("Product", data.GetProducts())
Me.ReportViewer1.LocalReport.DataSources.Add(rptDataSource)
Me.ReportViewer1.LocalReport.ReportPath = Server.MapPath("BarcodeReport.rdlc")
Me.ReportViewer1.LocalReport.Refresh()
End Sub
protected void Page_Load(object sender, EventArgs e)
{
//Create an instance of Barcode Professional
Neodynamic.WebControls.BarcodeProfessional.BarcodeProfessional bcp = new Neodynamic.WebControls.BarcodeProfessional.BarcodeProfessional();
//Barcode settings
bcp.Symbology = Neodynamic.WebControls.BarcodeProfessional.Symbology.Code128;
bcp.BarHeight = 0.25f;
//Fill the object datasource.
//NOTE: You may connect to a SQL Server Database and create Product objects based on data returned from such source.
Catalog data = new Catalog();
//Create random product info
string prodId;
string prodName;
byte[] prodBarcode;
for (int i = 0; i < 10; i++)
{
//Random product info
prodId = Guid.NewGuid().ToString().Substring(0, 10);
prodName = "Product " + prodId;
//Set the value to encode
bcp.Code = prodId;
//Generate the barcode image and store it into the Barcode Column
prodBarcode = bcp.GetBarcodeImage(System.Drawing.Imaging.ImageFormat.Png);
//Add new product
data.AddProduct(new Product(prodId, prodName, prodBarcode));
}
//Create Report Data Source
Microsoft.Reporting.WebForms.ReportDataSource rptDataSource = new Microsoft.Reporting.WebForms.ReportDataSource("Product", data.GetProducts());
this.ReportViewer1.LocalReport.DataSources.Add(rptDataSource);
this.ReportViewer1.LocalReport.ReportPath = Server.MapPath("BarcodeReport.rdlc");
this.ReportViewer1.LocalReport.Refresh();
}
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Button1.Click
'Create an instance of Barcode Professional
Dim bcp As New Neodynamic.WebControls.BarcodeProfessional.BarcodeProfessional()
'Barcode settings
bcp.Symbology = Neodynamic.WebControls.BarcodeProfessional.Symbology.Code128
bcp.BarHeight = 0.25F
'Fill the object datasource.
'NOTE: You may connect to a SQL Server Database and create Product objects based on data returned from such source.
Dim data As New Catalog()
'Create random product info
Dim prodId As String
Dim prodName As String
Dim prodBarcode As Byte()
Dim i As Integer
For i = 1 To 10
'Random product info
prodId = Guid.NewGuid().ToString().Substring(0, 10)
prodName = "Product " + prodId
'Set the value to encode
bcp.Code = prodId
'Generate the barcode image and store it into the Barcode Column
prodBarcode = bcp.GetBarcodeImage(System.Drawing.Imaging.ImageFormat.Png)
'Add new product
data.AddProduct(New Product(prodId, prodName, prodBarcode))
Next
'Create ReportViewer
Dim viewer As New Microsoft.Reporting.WebForms.ReportViewer()
'Create Report Data Source
Dim rptDataSource As New Microsoft.Reporting.WebForms.ReportDataSource("Product", data.GetProducts())
viewer.LocalReport.DataSources.Add(rptDataSource)
viewer.LocalReport.ReportPath = Server.MapPath("BarcodeReport.rdlc")
'Export to PDF
Dim pdfContent As Byte() = viewer.LocalReport.Render("PDF", Nothing, Nothing, Nothing, Nothing, Nothing, Nothing)
'Return PDF
Me.Response.Clear()
Me.Response.ContentType = "application/pdf"
Me.Response.AddHeader("Content-disposition", "attachment; filename=BarcodeReport.pdf")
Me.Response.BinaryWrite(pdfContent)
Me.Response.End()
End Sub
private void button1_Click(object sender, EventArgs e)
{
//Create an instance of Barcode Professional
Neodynamic.WebControls.BarcodeProfessional.BarcodeProfessional bcp = new Neodynamic.WebControls.BarcodeProfessional.BarcodeProfessional();
//Barcode settings
bcp.Symbology = Neodynamic.WebControls.BarcodeProfessional.Symbology.Code128;
bcp.BarHeight = 0.25f;
//Fill the object datasource.
//NOTE: You may connect to a SQL Server Database and create Product objects based on data returned from such source.
Catalog data = new Catalog();
//Create random product info
string prodId;
string prodName;
byte[] prodBarcode;
for (int i = 0; i < 10; i++)
{
//Random product info
prodId = Guid.NewGuid().ToString().Substring(0, 10);
prodName = "Product " + prodId;
//Set the value to encode
bcp.Code = prodId;
//Generate the barcode image and store it into the Barcode Column
prodBarcode = bcp.GetBarcodeImage(System.Drawing.Imaging.ImageFormat.Png);
//Add new product
data.AddProduct(new Product(prodId, prodName, prodBarcode));
}
//Create ReportViewer
Microsoft.Reporting.WebForms.ReportViewer viewer = new Microsoft.Reporting.WebForms.ReportViewer();
//Create Report Data Source
Microsoft.Reporting.WebForms.ReportDataSource rptDataSource = new Microsoft.Reporting.WebForms.ReportDataSource("Product", data.GetProducts());
viewer.LocalReport.DataSources.Add(rptDataSource);
viewer.LocalReport.ReportPath = Server.MapPath("BarcodeReport.rdlc");
//Export to PDF
string mimeType;
string encoding;
string fileNameExtension;
string[] streams;
Microsoft.Reporting.WebForms.Warning[] warnings;
byte[] pdfContent = viewer.LocalReport.Render("PDF", null, out mimeType, out encoding, out fileNameExtension, out streams, out warnings);
//Return PDF
this.Response.Clear();
this.Response.ContentType = "application/pdf";
this.Response.AddHeader("Content-disposition", "attachment; filename=BarcodeReport.pdf");
this.Response.BinaryWrite(pdfContent);
this.Response.End();
}
We provide best-in-class customer service and support directly from members of our dev team! If we are available when you contact us, you will get a response in few minutes; otherwise the maximum turnaround is 24hs in most cases.