Barcode Professional for ASP.NET使用教程:条码图像保存到数据库或者XML文件

本文介绍如何使用BarcodeProfessional控件在ASP.NET Web应用程序中生成条码图像,并将其保存为XML文件中的字节数组。通过创建DataSet对象并利用BarcodeProfessional的GetBarcodeImage方法实现。

Barcode Professional里面有个专门的获取条码图像的方法,该方法可以用数组字节来表示条码图像生成,因此我们可以调用这种方法来将条码图像保存到数据库中或者XML文件。

在下面的示例中,我们将创建一个ASP.NET的Web应用程序,该应用可以通过DataSet对象把条码图像保存到XML文件。

步骤:

  • 打开.NET开发工具,如Visual Studio .NET 并创建一个新的ASP.NET Web应用
  • 拖放下列控件到设计界面:
    • Barcode Professional控件
    • TextBox控件
    • Button控件
    • Panel控件并加入到Literal 控件里
  • 设置 Barcode Professional's Symbology 属性 128码
  • 设置Panel's Visible属性 False
  • 双击按钮控件并将下列代码写入Button1_Click 事件程序

VB

'Set the value to encode
BarcodeProfessional1.Code = TextBox1.Text
'Create a DataSet and save the barcode image
Dim ds As DataSet = New DataSet("MyDataSet")
Dim dt As DataTable = New DataTable("MyTable")
ds.Tables.Add(dt)
'Create a column to hold the barcode image
Dim dc As DataColumn = New DataColumn("BarcodeImage", GetType(Byte()))
dt.Columns.Add(dc)
'Create a new row
Dim dr As DataRow = dt.NewRow()
'Save the barcode image
dr("BarcodeImage") = BarcodeProfessional1.GetBarcodeImage(System.Drawing.Imaging.ImageFormat.Gif)
dt.Rows.Add(dr)
'Show the DataSet content
Literal1.Text = Server.HtmlEncode(ds.GetXml())
Panel1.Visible = True


C#

//Set the value to encode
BarcodeProfessional1.Code = TextBox1.Text;
//Create a DataSet and save the barcode image
DataSet ds = new DataSet("MyDataSet");
DataTable dt = new DataTable("MyTable");
ds.Tables.Add(dt);
//Create a column to hold the barcode image
DataColumn dc = new DataColumn("BarcodeImage", typeof(byte[]));
dt.Columns.Add(dc);
//Create a new row
DataRow dr = dt.NewRow();
//Save the barcode image
dr["BarcodeImage"] = BarcodeProfessional1.GetBarcodeImage(System.Drawing.Imaging.ImageFormat.Gif);
dt.Rows.Add(dr);
//Show the DataSet content
Literal1.Text = Server.HtmlEncode(ds.GetXml());
Panel1.Visible = true;


运行创建的ASP.NET Web应用程序,你将看到一下输出

Barcode
Barcode
【Barcode Professional for ASP.NET下载】
GRANT OF REDISTRIBUTION · Redistributable code. You cannot redistribute any part of THE PRODUCT, except the run-time assemblies (DLL files). · SDK, WPF and Windows Forms Versions of THE PRODUCT If you are a licensee of the “SDK Version” or “WPF Version” or “Windows Forms Version” of THE PRODUCT, then you are granted a license as a single individual to distribute THE PRODUCT royalty-free with an unlimited number of different compiled executables, provided they are developed solely by you. · ASP.NET Version of THE PRODUCT If you are a licensee of the “ASP.NET Version” of THE PRODUCT, then you are granted a license as a single individual to distribute THE PRODUCT royalty-free along with an unlimited number of different web-based solutions served from a SINGLE WEB SERVER (regardless of the number of CPUs in that server), provided they are developed solely by you. For distribution, hosting or transmittal by more than ONE WEB SERVER, you are required to upgrade to or purchase “Small Business” or “Corporate” licenses (which permit distribution to additional servers). Neodynamic does not charge for test servers. · Reporting Services Version of THE PRODUCT If you are a licensee of the “Reporting Services Version” of THE PRODUCT, you are granted a license as a single individual to distribute THE PRODUCT royalty-free along with an unlimited number of different Reporting Services solutions served from a SINGLE SQL SERVER REPORT SERVER (regardless of the number of CPUs in that server), provided they are developed solely by you. For distribution, hosting or transmittal by more than ONE SQL SERVER REPORT SERVER, you are required to upgrade to or purchase “Small Business” or “Corporate” licenses (which permit distribution to additional servers). Neodynamic does not charge for test servers.
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值