Link Search Menu Expand Document

Getting Started in ASP.NET

The following sample demonstrates how to read barcode from photo image using Bytescout BarCode Reader SDK for .NET

Create new ASP.NET project and add the following control into Default.aspx page: 1) Image control named Image1 and 2) Listbox control named ListBox1;

Create new ASP.NET project and add the following control into Default.aspx page: 1) Image control named Image1 and 2) Listbox control named ListBox1;

Please find copy of code for Default.aspx and corresponding Default.aspx.vb(or .cs) file.

<legacyBold xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5">Default.aspx:</legacyBold>
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="SimpleWebTestSharp._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Simple Web Barcode Reader Tester (C#)</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <div>
            <br />
            <asp:ListBox ID="ListBox1" runat="server"></asp:ListBox><br />
            <br />
            <asp:Image ID="Image1" runat="server" />&nbsp;</div>

    </div>
    </form>
</body>
</html>
        <legacyBold xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5">Default.aspx.cs:</legacyBold>
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using Bytescout.BarCodeReader;

namespace SimpleWebTestSharp
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Image1.ImageUrl = "BarcodePhoto.jpg";

            Reader reader = new Reader();
            reader.BarcodeTypesToFind.Code39 = true;

            // reader.MediumTrustLevelCompatible = true; // uncomment this line to enable Medium Trust compatible mode (slows down the recognition process as direct image data access is disabled in Medium Trust mode)

            reader.ReadFromFile(Server.MapPath("BarcodePhoto.jpg"));

            foreach (FoundBarcode barcode in reader.FoundBarcodes)
                ListBox1.Items.Add(String.Format("{0} : {1}", barcode.Type, barcode.Value));
        }
    }
}

Copyright © 2016 - 2021 ByteScout