1
Contributor
1
Reply
3
Views
7 Years
Discussion Span
Last Post by MARKAND911
0

After a long Research i found this code to Scan a document using WiaClass in ASP.NET

WiaClass wiaManager = null;		// WIA manager COM object
CollectionClass wiaDevs = null;		// WIA devices collection COM object
ItemClass wiaRoot = null;		// WIA root device COM object
CollectionClass wiaPics = null;		// WIA collection COM object
ItemClass wiaItem = null;		// WIA image COM object
try
    {
      string fileName = "myFile";
      wiaManager = new WiaClass();	// create COM instance of WIA manager

  wiaDevs = wiaManager.Devices as CollectionClass;// call Wia.Devices to get all devices

   if ((wiaDevs == null) || (wiaDevs.Count == 0))
   {
        Response.Write("<script>alert('No Scanner found');</script>");
        return;
   }
   else
   {
       object selectUsingUI = System.Reflection.Missing.Value;			
       wiaRoot = (ItemClass)wiaManager.Create(ref selectUsingUI);//letUser select device
       
     if(wiaRoot == Null	)
        return;

    // this call shows the common WIA dialog to let the user select a picture:
     wiaPics = wiaRoot.GetItemsFromUI(WiaFlag.SingleImage, WiaIntent.ImageTypeColor) as     CollectionClass;
              
      if (wiaPics == null)
            return;
      bool takeFirst = true;	         // this sample uses only one single picture
      string ImgName = Server.MapPath("~\\thumbnails").ToString() + "\\" + fileName;
    
     foreach (object wiaObj in wiaPics)	// enumerate all the pictures the user selected
      {
          if (takeFirst)
          {
          wiaItem = (ItemClass)Marshal.CreateWrapperOfType(wiaObj, typeof(ItemClass));
          // transfer picture to our temporary file
          wiaItem.Transfer(ImgName + ".jpg", false); 
          makeThumbnail(fileName + ".jpg");        
     takeFirst = false;								
    }
    Marshal.ReleaseComObject(wiaObj);		
   }
}
}
catch (Exception ee)
{
}
finally
(
if (wiaItem != null)
    Marshal.ReleaseComObject(wiaItem);		// release WIA image COM object
if (wiaPics != null)
    Marshal.ReleaseComObject(wiaPics);		// release WIA collection COM object
if (wiaRoot != null)
    Marshal.ReleaseComObject(wiaRoot);		// release WIA root device COM object
if (wiaDevs != null)
    Marshal.ReleaseComObject(wiaDevs);	// release WIA devices collection COM object
if (wiaManager != null)
    Marshal.ReleaseComObject(wiaManager);	// release WIA manager COM object
}
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.