HOW TO CREATE BARCODE USING ASP.NET AND C#

Words
226
Reading
2 min
Listen
Play
7y

HERE IN THIS .NET Tutorial WE WILL CREATE BARCODE USING ASP.NET AND C#

Step 1:

First Install IDAutomationCode39 In Your System,Link Below To Download.

Download IDAutomationCode39 Zip File Link :- http://www.idautomation.com/fonts/free/IDAutomationCode39.zip

Step 2 : Create Webform

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="BarcodeCreator.WebForm1" %>

<!DOCTYPE html>

<html>

<head runat="server">

    <title></title>

</head>

<body>

    <form id="form1" runat="server">

        <asp:TextBox ID="txtCode" runat="server"></asp:TextBox>

<asp:Button ID="btnGenerate" runat="server" Text="Generate" OnClick="btnGenerate_Click"/>

<hr/>

<asp:PlaceHolder ID="plBarCode" runat="server"/>

    </form>

</body>

</html>

Step 3 : Backend C# Code

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Drawing;

using System.Drawing.Imaging;

using System.IO;

namespace BarcodeCreator

{

public partial class WebForm1 : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

}

protected void btnGenerate_Click(object sender, EventArgs e)

{

string barcode = txtCode.Text;

System.Web.UI.WebControls.Image imgBarCode = new System.Web.UI.WebControls.Image();

using (Bitmap bitMap = new Bitmap(barcode.Length * 40, 80))

{

using (Graphics graphics = Graphics.FromImage(bitMap))

{

Font oFont = new Font("IDAutomationHC39M",16);

PointF point = new PointF(2f,2f);

SolidBrush blackBrush = new SolidBrush(Color.Black);

SolidBrush whiteBrush = new SolidBrush(Color.White);

graphics.FillRectangle(whiteBrush, 0, 0, bitMap.Width, bitMap.Height);

graphics.DrawString("*" + barcode + "*", oFont, blackBrush, point);

}

using (MemoryStream ms = new MemoryStream())

{

bitMap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);

byte[] byteImage = ms.ToArray();

Convert.ToBase64String(byteImage);

imgBarCode.ImageUrl = "data:image/png;base64," + Convert.ToBase64String(byteImage);

}

plBarCode.Controls.Add(imgBarCode);

}

}

}

}

If You Haven't Subscribers My Channel Than Please Subscribers It And Even Share It Link Of

My Channnel :- https://www.youtube.com/channel/UCdIDIGUh3rL9A_Yt_tbZmkg Please Go And Subscribers It

HOW TO CREATE BARCODE USING ASP.NET AND C# | Ecency