I hope that someone will come across this - I'm trying to capture images from a document scanner using WIA, but on random machines when I try to transfer the result of the image - WIA reports "File exists. - HRESULT: 0x80070050)." On all machines with this problem, the initial use of the software was successful.
I can successfully connect to the scanner, request a name, manufacturer, etc.
I determined that I can successfully scan the image if I run the code under an alternative user account (use the right mouse button to start as an administrator). However, running the code under the same elevated user account results in the same error.
NOTE. The exception is on Item1.Transfer - so until now I have not provided the WIA path to the file, so this cannot be the file to which it refers.
WIA.DeviceManager DeviceManager1 = new WIA.DeviceManagerClass();
WIA.Device Scanner = DeviceManager1.DeviceInfos[i].Connect();
WIA.Item Item1 = null;
foreach (WIA.Item CurrentItem in Scanner.Items) {
Item1 = CurrentItem;
break;
}
WIA.ImageFile Image1 = new WIA.ImageFile();
Image1 = (WIA.ImageFile)Item1.Transfer(WIA.FormatID.wiaFormatJPEG);
Image1.SaveFile(Path.Combine(Path.GetTempPath(), Path.GetRandomFileName() + @"\scan" + DateTime.Now.Ticks + ".jpg");
The most logical answer is that the WIA stores a temporary file during image capture, which I do not know about, and it cannot overwrite the previous scan. Does anyone know where this could be?
source
share