'Trouble with transfer function in WIA C#

I have a problem with the below code. I want to scan a document by clicking a button in a WinForms C# application.

I use WIA, Visual studio and the scanner Fujitsu N7100A working with Windows 8. I am following a tutorial online for using WIA.

But the program doesn't run as expected. It seems to break down at the Transfer method.

            // Create a DeviceManager instance 
            var deviceManager = new DeviceManager();
            // Create an empty variable to store the scanner instance
            DeviceInfo firstScannerAvailable = null;
            // Loop through the list of devices to choose the first available 
            AddLogs(deviceManager.DeviceInfos.Count.ToString(), filename);
            foreach (DeviceInfo d in deviceManager.DeviceInfos)
            {
                if (d.Type == WiaDeviceType.ScannerDeviceType)
                {
                    firstScannerAvailable = d;
                }
            }
            // Connect to the first available scanner 
            var device = firstScannerAvailable.Connect();
            // Select the scanner 
            var scannerItem = device.Items[0];
            // Retrieve a image in JPEG format and store it into a variable 
            var imageFile = (ImageFile)scannerItem.Transfer(FormatID.wiaFormatPNG);
            //Save the image in some path with filename 
            var path = @"C:\Documents\scan.png";
            if (File.Exists(path))
            {
                File.Delete(path);
            }
            // Save image ! 
            imageFile.SaveFile(path);

I just have to remove the addition of lines in the file of log.



Solution 1:[1]

This is much more of a workaround since i have no idea about your scanner.

I would assume that all scanners has a drive where they store their scanned documents, like mine, So i would suggest that you read all available drives loop through them check for DriveType and VolumeLabel and then read it's files and copy the document where you want

Something like this :

foreach (var item in DriveInfo.GetDrives())
        {
            //VolumeLabel differs from a scanner to another
            if (item.VolumeLabel == "Photo scan" && item.DriveType == DriveType.Removable)
            {
                foreach (var obj in Directory.GetFiles(item.Name))
                {
                    File.Copy(obj, "[YOUR NEW PATH]");
                    break;
                }
                break;
            }
        }

Solution 2:[2]

Finaly a TWAIN application work with this scanner. I will work with that. I don't said why do that work with TWAIN and not with WIA but that the reality. Sorry for this waste of time. Thank you for the answers. Have a nice day.

Solution 3:[3]

I am currently solving this very problem. It seems the N7100A driver sets the Pages property of the device to 0, which should mean continous scanning, but the transfer method is unable to handle this value. You must set that property to 1:

var pages = 1;

// Not all devices have this property, but Fujitsu N7100A has.
device.Properties["Pages"]?.set_Value(ref pages);

Solution 4:[4]

I think the problem is here

var scannerItem = device.Items[0];

as WIA indexes are NOT zero based so it should be 1 instead

var scannerItem = device.Items[1];

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Léna Yenshua
Solution 3
Solution 4 hkhk