如何使用Windows服务搜索子文件夹vb.net?

时间:2016-07-20 16:27:09

标签: vb.net windows-services

我的代码出现问题,我的想法是在文件夹中找到一个文件,但这是一个远程文件夹,如果它找不到它,它有很多子文件夹,那么它应该查找它在另一个文件夹中,但它似乎无法工作,任何人都可以帮助我吗?感谢您的帮助:)。

Dim dt2 As New System.Data.DataTable()
        Dim query2 As String = "SELECT juzgado, rutaPDF FROM mismoCorreo WHERE DATEPART(DAY, BirthDate) = @Day AND DATEPART(MONTH, BirthDate) = @Month"
        Dim constr2 As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
        Using con As New SqlConnection(constr2)
            Using cmd As New SqlCommand(query2)
                cmd.Connection = con
                cmd.Parameters.AddWithValue("@Day", DateTime.Today.Day)
                cmd.Parameters.AddWithValue("@Month", DateTime.Today.Month)
                Using sda As New SqlDataAdapter(cmd)
                    sda.Fill(dt2)
                End Using
            End Using
        End Using
        For Each row As DataRow In dt2.Rows
            Dim juzgado As String = row("juzgado").ToString()
            Dim nombre_archivo As String = row("rutaPDF").ToString()

            If (juzgado = "PRIMERO DE LO FAMILIAR") Then

                enviar = "\\172.16.20.101\SisInt\Juzgados\acuerdos\J92016SEM2" & "\" & nombre_archivo & ".docx"


            ElseIf (juzgado = "SEGUNDO DE LO FAMILIAR") Then

                enviar = "\\172.16.20.101\SisInt\Juzgados\acuerdos\J102016SEM2" & "\" & nombre_archivo & ".docx"
            End If

        Next


        For index = 0 To ListaArchivos.Count - 1

            Dim wordApplication = New Microsoft.Office.Interop.Word.Application()
            Dim wordDocument As Document = Nothing

            Dim paramSourceDocPath As String = ListaArchivos.Item(index)

            Dim paramExportFilePath As String = "\\172.16.20.101\SisInt\Convertidos" + "\" + ListaNombres.Item(index) + ".pdf"
            Dim paramExportFormat As WdExportFormat =
            WdExportFormat.wdExportFormatPDF
            Dim paramOpenAfterExport As Boolean = False
            Dim paramExportOptimizeFor As WdExportOptimizeFor =
            WdExportOptimizeFor.wdExportOptimizeForPrint
            Dim paramExportRange As WdExportRange =
            WdExportRange.wdExportAllDocument
            Dim paramStartPage As Int32 = 0
            Dim paramEndPage As Int32 = 0
            Dim paramExportItem As WdExportItem =
            WdExportItem.wdExportDocumentContent
            Dim paramIncludeDocProps As Boolean = True
            Dim paramKeepIRM As Boolean = True
            Dim paramCreateBookmarks As WdExportCreateBookmarks =
            WdExportCreateBookmarks.wdExportCreateWordBookmarks
            Dim paramDocStructureTags As Boolean = True
            Dim paramBitmapMissingFonts As Boolean = True
            Dim paramUseISO19005_1 As Boolean = False

            Try
                'Abrir documento basados en el que selecciono
                wordDocument = wordApplication.Documents.Open(paramSourceDocPath)

                ' Exportar al formato deseado
                If Not wordDocument Is Nothing Then
                    wordDocument.ExportAsFixedFormat(paramExportFilePath,
                    paramExportFormat, paramOpenAfterExport,
                    paramExportOptimizeFor, paramExportRange, paramStartPage,
                    paramEndPage, paramExportItem, paramIncludeDocProps,
                    paramKeepIRM, paramCreateBookmarks,
                    paramDocStructureTags, paramBitmapMissingFonts,
                    paramUseISO19005_1)
                End If
            Catch ex As Exception
                'MessageBox.Show(ex.Message)
                'Registro en base de datos fecha hora y ex.message 
            Finally

                If Not wordDocument Is Nothing Then
                    wordDocument.Close(False)
                    wordDocument = Nothing
                End If


                If Not wordApplication Is Nothing Then
                    wordApplication.Quit()
                    wordApplication = Nothing
                End If

                GC.Collect()
                GC.WaitForPendingFinalizers()
                GC.Collect()
                GC.WaitForPendingFinalizers()

            End Try

        Next

0 个答案:

没有答案