I'm hoping someone has come across this - I'm trying to capture images from a document scanner using WIA, however on random machines when attempting to transfer the image result - WIA reports "The file exists. - HRESULT: 0x80070050)". On All machines with this issue, initial use of the software was successful.
I am able to connect successfully to the scanner, query for Name, Manufacturer,etc.
I've determined that i can successfully scan an image, if i run the code under an alternative user account (Using right-click run as administrator). However, running the code under the same user account with elevated privledges results in the same error.
NOTE: Exception is happening on Item1.Transfer - so up until this point i haven't yet provided WIA with a file path, so this can't be the file it's referring to.
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();
//Attempt To Capture Scan
Image1 = (WIA.ImageFile)Item1.Transfer(WIA.FormatID.wiaFormatJPEG);
//Save To File
Image1.SaveFile(Path.Combine(Path.GetTempPath(), Path.GetRandomFileName() + @"\scan" + DateTime.Now.Ticks + ".jpg");
The most logical answer is that WIA is storing a temporary file during image capture - that i'm not aware of - and it is unable to overwrite a previous scan. Does anyone know where this might be?