Click here to Skip to main content
15,891,529 members
Articles / Web Development / ASP.NET

Scan and Upload Documents in ASP.NET MVC App using Dynamic Web TWAIN

10 Jul 2013CPOL3 min read 60.6K   4.3K   11  
This article will show you how to scan and upload documents in an ASP.NET Model View Controller (MVC) 3 web application. We will be using the Dynamic Web TWAIN scanning SDK which is well used to expedite development and deployment of such an application.

This article is in the Product Showcase section for our sponsors at CodeProject. These articles are intended to provide you with information on products and services that we consider useful and of value to developers.

var DW_ProductName = "Dynamic Web TWAIN";
var DW_ObjectName = "DynamicWebTWAINObject";
var DW_IsTrial = true;     // If this is a trial version. User can change it.
var DW_VersionCode = "9,0"; // The version of DWT. ActiveX will use this to determin if it is necessary to upgrade the client. Use ',' to separate the numbers. 
var DW_Version = "9.0"; 
var DW_Width = 580;        // The width of the main control. User can change it.
var DW_Height = 450;       // The width of the main control. User can change it.
var DW_PKGPath = "../Content/DynamicWebTWAINMacEditionTrial.pkg";     //The relative path of the PKG file. User need to change it.
var DW_MSIPath = "../Content/DynamicWebTWAINPlugIn.msi";         //The relative path of the MSI file. User need to change it.
var DW_CABX86Path = "../Content/DynamicWebTWAIN.cab";         //The relative path of the x86 cab file. User need to change it.
var DW_CABX64Path = "../Content/DynamicWebTWAINx64.cab";      //The relative path of the x64 cab file. User need to change it.
var DW_MIMETYPE = "Application/DynamicWebTwain-Plugin";
var DW_PROCLASSID = "5220cb21-c88d-11cf-b347-00aa00a28331";  
var DW_FULLCLASSID = "E7DA7F8D-27AB-4EE9-8FC0-3FEC9ECFE758"; 
var DW_TRAILCLASSID = "FFC6F181-A5CF-4ec4-A441-093D7134FBF2";    
var DW_DemoPath = "http://www.dynamsoft.com/demo/DWT/";
var DW_DefaultSaveImageName = "WebTWAINImage";
var DW_NoDrivers = "No TWAIN compatible drivers detected:";


function InitContrlDetail() {
    var ObjString = "<ul id='divTwainType' style='height:70px; background:#f0f0f0;'> ";
    ObjString += "<li style='padding-left:12px;'>";
    ObjString += "<label for = 'ShowUI'><input type='checkbox' id='ShowUI' />Show UI&nbsp;</label>";
    ObjString += "<label for = 'ADF'><input type='checkbox' id='ADF' />ADF&nbsp;</label>";
    ObjString += "<label for = 'Duplex'><input type='checkbox' id='Duplex'/>Duplex</label></li>";
    ObjString += "<li style='padding-left:15px;'>Pixel Type:";
    ObjString += "<label for='BW'><input type='radio' id='BW' name='PixelType'/>B&amp;W </label>";
    ObjString += "<label for='Gray'><input type='radio' id='Gray' name='PixelType'/>Gray</label>";
    ObjString += "<label for='RGB'><input type='radio' id='RGB' name='PixelType'/>Color</label></li>";
    ObjString += "<li style='padding-left:15px;'>";
    ObjString += "<label for='Resolution'>Resolution:<select size='1' id='Resolution'><option value = ''></option></select></label></li>";
    ObjString += "</ul>";
    document.getElementById("divProductDetail").innerHTML = ObjString;
}

function ShowMessage() {

}

function InitUpgrade() {

}

function InitiateInputs() {
    var allinputs = document.getElementsByTagName("input");
    for (var i = 0; i < allinputs.length; i++) {
        if (allinputs[i].type == "checkbox") {
            allinputs[i].checked = false;
        }
        else if (allinputs[i].type == "text") {
            allinputs[i].value = "";
        }
    }
    document.getElementById("Gray").checked = true;
    document.getElementById("imgTypejpeg2").checked = true;
    document.getElementById("imgTypejpeg").checked = true;
    
    if (!DW_InWindows) {
        document.getElementById("btnEditor").style.display = "none";
        document.getElementById("tblLoadImage").style.height = "170";
        document.getElementById("notformac1").style.display = "none";
    }
}

function OnchangeInner() {
    document.getElementById("divTwainType").style.display = "";
    document.getElementById("btnScan").value = "Scan";
}

function ControlInit() {
    Resolution = document.getElementById("Resolution");
    Resolution.options.length = 0;
    Resolution.options.add(new Option("100", 100));
    Resolution.options.add(new Option("150", 150));
    Resolution.options.add(new Option("200", 200));
    Resolution.options.add(new Option("300", 300));
    
    document.getElementById("ADF").checked = true;
}


function AcquireImageInner() {
    if (DW_DWTSourceContainerID == "")
        DWObject.SelectSource();
    else
        DWObject.SelectSourceByIndex(document.getElementById(DW_DWTSourceContainerID).selectedIndex);
    DWObject.CloseSource();
    DWObject.OpenSource();
    DWObject.IfShowUI = document.getElementById("ShowUI").checked;

    var i;
    for (i = 0; i < 3; i++) {
        if (document.getElementsByName("PixelType").item(i).checked == true)
            DWObject.PixelType = i;
    }
    DWObject.Resolution = Resolution.value;
    DWObject.IfFeederEnabled = document.getElementById("ADF").checked;
    DWObject.IfDuplexEnabled = document.getElementById("Duplex").checked;
    AppendMessage("Pixel Type: " + DWObject.PixelType + "<br />Resolution: " + DWObject.Resolution + "<br />");

    DWObject.IfDisableSourceAfterAcquire = true;
    DWObject.AcquireImage();
}

function ShowtblLoadImage_onclick() {
    switch (document.getElementById("tblLoadImage").style.visibility) {
        case "hidden": document.getElementById("tblLoadImage").style.visibility = "visible";
            document.getElementById("Resolution").style.visibility = "hidden";
            break;
        case "visible":
            document.getElementById("tblLoadImage").style.visibility = "hidden";
            document.getElementById("Resolution").style.visibility = "visible";
            break;
        default: break;
    }
    document.getElementById("tblLoadImage").style.top = ds_gettop(document.getElementById("pNoScanner")) + pNoScanner.offsetHeight + "px";
    document.getElementById("tblLoadImage").style.left = ds_getleft(document.getElementById("pNoScanner")) + 0 + "px";
    return false;
}
function ClosetblLoadImage_onclick() {
    document.getElementById("tblLoadImage").style.visibility = "hidden";
    document.getElementById("Resolution").style.visibility = "visible";
    return false;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Canada Canada
Dynamsoft has more than 15 years of experience in TWAIN SDKs, imaging SDKs and version control solutions.

Our products include:

TWAIN SDK
- Dynamic Web TWAIN: a TWAIN scanning SDK optimized for web document management applications.
- Dynamic .NET TWAIN: a .NET TWAIN and Directshow Image Capture SDK for WinForms/WPF applications.

Imaging SDKs
- Barcode Reader for Windows, Linux, macOS, iOS, Android and Raspberry Pi.
- OCR addon for both web and .NET TWAIN SDKs

Version Control
- SourceAnywhere: a SQL server-based source control solution. Both on-premise and hosting options are provided.

http://www.dynamsoft.com/
This is a Organisation

21 members

Comments and Discussions