Public Function CheckFormat(ByVal ImportedFile As DataTable, ByVal TemplateFile As DataTable) As Boolean
Dim dtFileTable As DataTable = ImportedFile
Dim dtTmplateTable As DataTable = TemplateFile
Dim lbResult As Boolean = True
Try
If dtFileTable.Columns.Count = dtTmplateTable.Columns.Count Then
Dim liColCount As Integer = 0
For liColCount = 0 To dtFileTable.Columns.Count - 1
If LCase(dtFileTable.Columns(liColCount).Caption) = LCase(dtTmplateTable.Columns(liColCount).Caption) Then
Continue For
Else
lsFormatStatus = "Uploaded File is not in Proper Format
lbResult = False
Exit For
End If
Next
If lbResult Then
If Not (dtFileTable.Rows.Count >= 1) Then
lsFormatStatus = "Uploaded File has no data
lbResult = False
End If
End If
Else
lsFormatStatus = "Uploaded File is not in Proper Format"
lbResult = False
End If
Catch ex As Exception
'objDB.LogError(ex)
lsFormatStatus = "Uploaded File is not in Proper Format"
lbResult = False
End Try
Return lbResult
End Function
Private Sub btnsubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsubmit.Click
Dim lsPath As String = txtPath.Text.Trim()
lblmsg.Text = ""
Dim loDSTemplate As New System.Data.DataSet()
xlsWB = xlsApp.Workbooks.Open(lsPath, False, False)
xlsSheet = xlsWB.Worksheets(1)
Me.Refresh()
lnktemplate.Text = String.Empty
Dim lsConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & lsPath & ";Extended Properties=Excel 8.0;"
''You must use the $ after the object you reference in the spreadsheet
Dim loDBExcelTemplate As New System.Data.OleDb.OleDbDataAdapter("SELECT * FROM [" & xlsSheet.Name & "$]", lsConn)
loDBExcelTemplate.TableMappings.Add("Table", "ExcelFile")
loDBExcelTemplate.Fill(loDSTemplate)
Dim Templated As DataTable = New DataTable
Templated.Columns.Add("IP")
Templated.Columns.Add("Port")
If CheckFormat(loDSTemplate.Tables(0), Templated) Then
(Do ping and telnet)
Else
Lblerror.text="Not in proper format"
End Sub