Link to home
Start Free TrialLog in
Avatar of mathieu_cupryk
mathieu_cuprykFlag for Canada

asked on

need to convert change the Dim m match from vb.net to Fore each string() in line

 Dim Conn As New SqlConnection(ConfigurationManager.AppSettings("SqlString"))
            Dim Cmd As New SqlCommand("select distinct Filename from cdr_zip_file", Conn)
            Conn.Open()
            Dim Ds As New DataSet()
            Dim Da As New SqlDataAdapter(Cmd)
            Da.Fill(Ds, "ZipTable")
            Conn.Close()

            Dim strReplyFromCheckFile As String 'TP
            Dim Dt As DataTable = Ds.Tables("ZipTable")
            Dt.PrimaryKey = New DataColumn() {Dt.Columns("Filename")}
          Dim m As Match

            For Each m In mch

                If Dt.Rows.Find(m.Groups(2).Value) Is Nothing Then

                    strReplyFromCheckFile = Utilities.CheckFileTobeDownloaded(m.Groups(2).Value) 'TP

                   


                        Try
                            Utilities.WriteToDB(MessageTypes.MessageTypeLog, Categories.CategoryCDRScrape, "System", "Downloading CDR file '" & m.Groups(2).Value & "'")

                            cli.DownloadFile(ConfigurationManager.AppSettings("CDRFilesPath") & m.Groups(1).Value, ConfigurationManager.AppSettings("TempFileLocation") & m.Groups(2).Value)

                            Try
                                Utilities.WriteToDB(MessageTypes.MessageTypeLog, Categories.CategoryCDRScrape, "System", "Writing CDR file '" & m.Groups(2).Value & "' zip components to production.")
                                ZipOperations.WriteZipComponentsToFTP(ConfigurationManager.AppSettings("TempFileLocation") & m.Groups(2).Value, _
                                              ConfigurationManager.AppSettings("FTPSite"), _
                                              ConfigurationManager.AppSettings("FTPUsername"), _
                                               ConfigurationManager.AppSettings("FTPPassword"))

                                Utilities.WriteToDB(MessageTypes.MessageTypeLog, Categories.CategoryCDRScrape, "System", "Finished processing CDR file '" & m.Groups(2).Value & "'")

                                Cmd = New SqlCommand("insert into cdr_zip_file (Filename) values (@ZipFileName)", Conn)
                                Cmd.Parameters.Add(New SqlParameter("@ZipFileName", SqlDbType.VarChar)).Value = m.Groups(2).Value
                                Conn.Open()
                                Cmd.ExecuteNonQuery()
                                Conn.Close()
                            Catch ex As Exception
                                Conn.Close()
                                Utilities.ReportException("System", _
                                                          ex, _
                                                          Categories.CategoryCDRScrape)
                            Finally
                                Dim Di As New System.IO.DirectoryInfo(ConfigurationManager.AppSettings("TempFileLocation"))
                                Dim Fi As System.IO.FileInfo
                                For Each Fi In Di.GetFiles()
                                    If Fi.CreationTime.CompareTo(DateTime.Now().AddDays(-10)) < 0 Then
                                        Fi.Delete()
                                    End If
                                Next
                            End Try
                        Catch ex As Exception
                            Conn.Close()
                            Utilities.ReportException("System", _
                                                      ex, _
                                                      Categories.CategoryCDRScrape)
                        End Try

                    End If 'TP

                End If
            Next
Dim Conn As New SqlConnection(ConfigurationManager.AppSettings("SqlString"))
            Dim Cmd As New SqlCommand("select distinct Filename from cdr_zip_file", Conn)
            Conn.Open()
            Dim Ds As New DataSet()
            Dim Da As New SqlDataAdapter(Cmd)
            Da.Fill(Ds, "ZipTable")
            Conn.Close()
 
            Dim strReplyFromCheckFile As String 'TP
            Dim Dt As DataTable = Ds.Tables("ZipTable")
            Dt.PrimaryKey = New DataColumn() {Dt.Columns("Filename")}
 
            ' Read each file and put in to string parse
            Dim ListofFiles() As String = GetFileList(reqFTPIn.Credentials, ConfigurationManager.AppSettings("FTPSite"))
For Each Str() In line
                If Dt.Rows.Find(m.Groups(2).Value) Is Nothing Then ''' this needs to be replave
 
-------------------------------------------------------------------
what do i do here i am not sure i am

Open in new window

Avatar of David H.H.Lee
David H.H.Lee
Flag of Malaysia image

Hi mathieu_cupryk,
You can always use this vb.net convertor for any c# conversion(from vb.net or vice versa)
http://www.developerfusion.com/tools/convert/vb-to-csharp/

Hope it helps. Please let us know if you need any further assistance.
Avatar of sunithnair
sunithnair

What is the value for m.Groups(2).Value? This could should work properly since you have already defined file name as primary key. Does your m.Groups(2).Value contain the filename?
Avatar of mathieu_cupryk

ASKER

I think I need to loop through the files

 Dim ListofFiles() As String = GetFileList(reqFTPIn.Credentials, ConfigurationManager.AppSettings("FTPSite"))

and check if the file name exist in the datatable.
How should I do ths?
it would be something like this?
For Each filename As String In filenames

check for file in dt
            Next
ASKER CERTIFIED SOLUTION
Avatar of sunithnair
sunithnair

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial