Create or Generate QR Code in ASP.Net using C#

  ASP.NET   Thursday, September 6, 2018   98 | No Comments Yet!!! | No Download | No Demo | Pawan kumar
 Tags: Create or Generate QR Code in ASP.Net using C#  QR Code in ASP.Net  Generate QR Code 


Here Pawan Kumar will explain how to Create or Generate QR Code in ASP.Net using C#


In previous post I have explained Perserve/Retain state for dynamically created ASP.Net Dynamic Controls ViewState on PostBack, Allow only AlphaNumeric ( Alphabets and Numbers) characters and space only in TextBox using Javascript and jQuery(Example & Demo), Export HTML Table to PDF in ASP.Net with C# using iTextSharp DLL Library, GridView in ASP.Net using c# tutorial, Disabled submit button after clicked using jQuery with example, Simple HTML5 Example (Canvas) with Example Source Code, and many more articles.

Now I will explain How to Create or Generate QR Code in ASP.Net using C#

So follow the steps to learn Create or Generate QR Code in ASP.Net using C#

Install Nuget Packages “Zxing.Net” library

ASP.NET Source Code:-

<html xmlns="">
<head runat="server">
<title>Create or Generate QR Code in ASP.Net using C#</title>
<form id="form1" runat="server">
<asp:TextBox ID="tbCode" runat="server"></asp:TextBox>
<asp:Button ID="btnGenerate" runat="server" Text="Generate QR Code" OnClick="btnGenerate_Click" />
<hr />
<asp:Image ID="imgQRCode" Width="100px" Height="100px" runat="server" Visible="false" />     <br /><br />
<asp:Button ID="btnRead" Text="Read QR Image" runat="server" OnClick="btnRead_Click" />  <br /><br />
<asp:Label ID="lblQRCode" runat="server"></asp:Label>

Code Behind:-

using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using ZXing;

public partial class GenerateQRCode : System.Web.UI.Page
protected void Page_Load(object sender, EventArgs e)

protected void btnGenerate_Click(object sender, EventArgs e)
protected void btnRead_Click(object sender, EventArgs e)
// Generate QRCode Method
private void GenerateCode(string name)
var writer = new BarcodeWriter();
writer.Format = BarcodeFormat.QR_CODE;
var result = writer.Write(name);
string path = Server.MapPath("~/images/QRImage.jpg");
var barcodeBitmap = new Bitmap(result);

using (MemoryStream memory = new MemoryStream())
using (FileStream fs = new FileStream(path, FileMode.Create, FileAccess.ReadWrite))
barcodeBitmap.Save(memory, ImageFormat.Jpeg);
byte[] bytes = memory.ToArray();
fs.Write(bytes, 0, bytes.Length);
imgQRCode.Visible = true;
imgQRCode.ImageUrl = "~/images/QRImage.jpg";

// Read Code from QR Image Method
private void ReadQRCode()
var reader = new BarcodeReader();
string filename = Path.Combine(Request.MapPath("~/images"), "QRImage.jpg");
// Detect and decode the barcode inside the bitmap
var result = reader.Decode(new Bitmap(filename));
if (result != null)
lblQRCode.Text = "QR Code: "+ result.Text;



So, In this tutorial we have learned, Create or Generate QR Code in ASP.Net using C#

Post Comments

if you have some suggestion, question, request on Create or Generate QR Code in ASP.Net using C#.

Please use the comment box to express your views.