EZTwain-它也在哪里写文件?

时间:2019-03-19 20:45:01

标签: vb.net scanning

一位同事离开工作,以确保每个签到的人都检入了旧扫描应用程序(VB.NET Win Forms)的最新版本的源代码。他没有。编译版本可以完美运行,但签入版本则不能。在使用Red Gate的.NET Reflector对工作版本进行反编译之后,我们得到以下代码。

应用程序使用EZTwain。我期望第EZTwain.DibWritePage(num2)行将文件写入指定的path。没有。其他一切都很好。

文件在哪里? DocLocation =“ C:\ Scanner \”并且该文件夹存在。

Private Sub cmdScan_Click(ByVal sender As Object, ByVal e As EventArgs) Handles cmdScan.Click
    Me.Cursor = Cursors.WaitCursor
    If (Me.SearchList.ListBoxReference.Length = 0) Then
        MessageBox.Show("Please input a Reference before proceeding.", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
        Me.SearchList.Focus()
        Me.Cursor = Cursors.Default
    Else
        Dim num As Integer = 1
        Dim str As String = Me.SearchList.ListBoxReference.Replace("/", "-")
        Dim path As String = (My.Settings.DocLocation & str & "_v0001.tif")
        Do While True
            Dim strArray As String()
            If Not File.Exists(path) Then
                Try
                    EZTwain.OrganizationLicense(My.Settings.EZTwainOrganisation, My.Settings.EZTwainKey)
                    EZTwain.SetHideUI(False)
                    EZTwain.SetFileAppendFlag(False)
                    EZTwain.SetJpegQuality(&H4B)
                    EZTwain.SetTiffCompression(2, 7)
                    EZTwain.SetResolution(CInt(Me.cboDefaultResolution.SelectedItem))
                    If EZTwain.OpenDefaultSource Then
                        EZTwain.SetXferCount(-1)
                        EZTwain.SetAutoScan(True)
                        EZTwain.SetMultiTransfer(True)
                        EZTwain.BeginMultipageFile(path)
                        Do While True
                            Dim num2 As System.IntPtr = EZTwain.Acquire(Me.Handle)
                            If (num2 <> 0) Then
                                EZTwain.DibWritePage(num2)
                                EZTwain.DIB_Free(num2)
                                If (EZTwain.State >= 6) Then
                                    Continue Do
                                End If
                            End If
                            EZTwain.CloseSource()
                            EZTwain.EndMultipageFile()
                            Exit Do
                        Loop
                    End If
                    If (EZTwain.LastErrorCode <> 0) Then
                        EZTwain.ReportLastError("Unable to scan.")
                        File.Delete(path)
                        Me.Cursor = Cursors.Default
                    Else
                        If (File.Exists(path) And (FileSystem.FileLen(path) < 20)) Then
                            File.Delete(path)
                        ElseIf File.Exists(path) Then
                            Dim num3 As Double = (CDbl(FileSystem.FileLen(path)) / 1000000)
                            Try
                                strArray = New String() {System.IO.Path.GetFileName(path), " (", num3.ToString("N3"), "Mb ", Convert.ToString(File.GetCreationTime(path)), ")"}
                                Me.lstDocuments.Items.Add(String.Concat(strArray))
                                Me.lstDocuments.Sorted = True
                                If My.Settings.ImagePreview Then
                                    Interaction.Shell((My.Settings.ImageViewer & " " & path), AppWinStyle.MaximizedFocus, False, -1)
                                End If
                                Me.lstDocuments.SelectedIndex = -1
                            Catch exception3 As Exception
                                Dim ex As Exception = exception3
                                CompilerServices.ProjectData.SetProjectError(ex)
                                Dim exception2 As Exception = ex
                                MessageBox.Show(("An error occurred while saving the file." & ChrW(13) & ChrW(10) & "Error - " & exception2.Message & ChrW(13) & ChrW(10) & "Please Try again."), Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Hand)
                                Me.Cursor = Cursors.Default
                                CompilerServices.ProjectData.ClearProjectError()
                                Exit Do
                            End Try
                        End If
                        Me.Cursor = Cursors.Default
                    End If
                Catch exception1 As Exception
                    Dim ex As Exception = exception1
                    CompilerServices.ProjectData.SetProjectError(ex)
                    Dim exception As Exception = ex
                    MessageBox.Show(("An error occurred while scanning the image." & ChrW(13) & ChrW(10) & "Error - " & exception.Message & ChrW(13) & ChrW(10) & "Please Try again."), Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Hand)
                    If File.Exists(path) Then
                        File.Delete(path)
                    End If
                    Me.Cursor = Cursors.Default
                    CompilerServices.ProjectData.ClearProjectError()
                End Try
                Exit Do
            End If
            num += 1
            strArray = New String() {My.Settings.DocLocation, str, "_v", num.ToString.PadLeft(4, "0"c), ".tif"}
            path = String.Concat(strArray)
        Loop
    End If
End Sub

1 个答案:

答案 0 :(得分:0)

路径在此处定义

 (My.Settings.DocLocation & str & "_v0001.tif")

然后在此处提供给twain软件:

  EZTwain.BeginMultipageFile(path)

如果您查看已编译的应用程序的exe.config,应该有一个定义为DocLocation的节点,该节点提供了要使用的路径。