How to scan documents in a ASP.NET Web Application?

Last Updated on 2018-10-10

Scan document in ASP.NET Web Form

Document scanning module in ASP.NET Web Form

As you know, ASP.NET is a server-side programming language and it cannot access client-side devices. To embed a document scanning module into your ASP.NET web application, you can use an ActiveX/Plugin to interact with the scanners. This article will show how to use the Dynamic Web TWAIN SDK to achieve that.

Dynamic Web TWAIN is a TWAIN SDK specifically designed for web applications. It allows you to capture images from TWAIN compatible scanners, digital cameras and capture cards.

Dynamic Web TWAIN supports all the mainstream browsers, including Internet Explorer (32 bit and 64 bit), Edge, Firefox, Chrome, Safari, on Windows, macOS, or Linux on the client side. It includes ActiveX and Plugin options to support document scanning in legacy browser versions. It also provides a HTML5 TWAIN SDK to support scanning in modern HTML5 browsers, such as Edge, latest versions of Internet Explorer, Chrome, Firefox, and Safari.

How to Scan Document in ASP.NET App with Dynamic Web TWAIN?

Dynamic Web TWAIN is a client-side imaging control and you can call all the APIs of Dynamic Web TWAIN in JavaScript. After scanning, you can save the images to local disk, web server, database or SharePoint libraries etc. Here we will show you how to upload the scanned images to web server in C# and VB.NET.

Scan Document (JavaScript)

[javascript]function DWT_AcquireImage() {
if (DWT_DWTSourceContainerID == "")
WebTWAIN.SelectSource();
else
WebTWAIN.SelectSourceByIndex(document.getElementById(DWT_DWTSourceContainerID).selectedIndex); //display the available scanners
WebTWAIN.CloseSource(); //to ensure the device is not in use
WebTWAIN.OpenSource();

WebTWAIN.IfFeederEnabled = true; //use ADF scanning
WebTWAIN.IfShowUI = false; //hide the user interface of the scanner
WebTWAIN.PixelType = 2;
WebTWAIN.Resolution =200;
WebTWAIN.AcquireImage(); //acquire images
}[/javascript]

[javascript]function btnUpload_onclick()
{
var strActionPage;
var strHostIP;

var CurrentPathName = unescape(location.pathname); // get current PathName in plain ASCII
var CurrentPath = CurrentPathName.substring(0, CurrentPathName.lastIndexOf("/") + 1);
strActionPage = CurrentPath + "SaveToFile.aspx"; //the ActionPage’s file path

strHostIP = "localhost"; //The host’s IP or name

WebTWAIN.HTTPPort = 80;
WebTWAIN.HTTPUploadThroughPost(strHostIP,0,strActionPage,"imageData.tif");

if (WebTWAIN.ErrorCode != 0)
alert(WebTWAIN.ErrorString);
else //succeded
alert("Image Uploaded successfully");
}[/javascript]

Upload Image (C#)

[javascript]<%@ Page Language="c#" AutoEventWireup="false" Debug="True"%>

<%
HttpFileCollection files = HttpContext.Current.Request.Files;
HttpPostedFile uploadfile = files["RemoteFile"];
uploadfile.SaveAs(System.Web.HttpContext.Current.Request.MapPath(".") + "/" + uploadfile.FileName);
%>[/javascript]

Upload Image (VB.NET)

[javascript]<%@ Page Language="vb" AutoEventWireup="false"%>
<%
Dim files As HttpFileCollection = HttpContext.Current.Request.Files
Dim uploadfile As HttpPostedFile = files("RemoteFile")

dim filePath
filePath = System.Web.HttpContext.Current.Request.MapPath(".") &amp; "/UploadedImages/"

If Not System.IO.Directory.Exists(filePath) Then
System.IO.Directory.CreateDirectory(filePath)
End If
filePath = filePath &amp; uploadfile.FileName

uploadfile.SaveAs(filePath)
%>[/javascript]

Download working samples →

To try Dynamic Web TWAIN in your document scanning project, you can download the 30-day free trial.


Let us know in the comments section below about your experience in creating your web-based ASP.NET document imaging applications.

 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Subscribe Newsletter

Subscribe to our mailing list to get the monthly update.

Subscribename@email.com