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

Sep 22, 2013

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)

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

    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
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;

if (WebTWAIN.ErrorCode != 0)
else //succeded
alert("Image Uploaded successfully");

Upload Image (C#)

<%@ 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);

Upload Image (VB.NET)

<%@ 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(".") & "/UploadedImages/"

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


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.

Subscribe Newsletter

Subscribe to our mailing list to get the monthly update.