private void AcquireToFile(int nWhich) { if (SelectedSource != 0) { int status = 0; int bError = 0; long FileFlags = 0; string tFileName = ""; int fileType = 0; switch (nWhich) { case 0: FileFlags = TwainAPI.DTWAIN_USELONGNAME | TwainAPI.DTWAIN_USENATIVE; TwainAPI.DTWAIN_SetBlankPageDetection(SelectedSource, 98.5, (int)TwainAPI.DTWAIN_BP_AUTODISCARD_ANY, DiscardBlankPages.Checked ? 1 : 0); FileTypeDlg fDlg = new FileTypeDlg(); fDlg.ShowDialog(); tFileName = fDlg.GetFileName(); StringBuilder szSourceName = new StringBuilder(tFileName); fileType = fDlg.GetFileType(); break; case 1: if (TwainAPI.DTWAIN_IsFileXferSupported(SelectedSource, TwainAPI.DTWAIN_ANYSUPPORT) == 0) { MessageBox.Show("Sorry. The selected driver does not have built-in file transfer support."); return; } if (TwainAPI.DTWAIN_IsFileXferSupported(SelectedSource, TwainAPI.DTWAIN_FF_BMP) == 0) { string sText = "Sorry. This demo program only supports built-in BMP file transfers.\r\n"; sText += "However, the DTWAIN library will support all built-in formats if your driver\r\n"; sText += "supports other formats."; MessageBox.Show(sText); return; } FileFlags = TwainAPI.DTWAIN_USESOURCEMODE | TwainAPI.DTWAIN_USELONGNAME; fileType = TwainAPI.DTWAIN_FF_BMP; tFileName = ".\\IMAGE.BMP"; MessageBox.Show("The name of the image file that will be saved is IMAGE.BMP\n"); break; } bError = TwainAPI.DTWAIN_AcquireFile(SelectedSource, tFileName, fileType, (int)FileFlags, TwainAPI.DTWAIN_PT_DEFAULT, /* Use default */ TwainAPI.DTWAIN_ACQUIREALL, /* Get all pages */ UseSourceUI.Checked ? 1 : 0, 1, /* Close Source when UI is closed */ ref status ); if (bError == 0) { MessageBox.Show("Error acquiring or saving file."); } else if (status == TwainAPI.DTWAIN_TN_ACQUIREDONE) { MessageBox.Show("Image file saved successfully"); } else { MessageBox.Show("The acquisition returned a status of " + status.ToString()); } } }