Forum Discussion
sameburn
10 months agoContributor II
Hi. I have been testing this. You can't use a data source / parser rule here because the column you are trying to fix is already in the next line. However, you can solve for this with a Connector BR and using the TextFieldParser class of the Microsoft.VisualBasic.FileIO namespace. In this example we are picking up the file from FileShare as csv with semi-colon delimiter
' Custom Import (don't forget to add and uncomment line below)
'Imports Microsoft.VisualBasic.FileIO
' Get File Path (FileShare)
Dim configSettings As AppServerConfigSettings = AppServerConfig.GetSettings(si)
Dim fullPath As String = Path.Combine(FileShareFolderHelper.GetGroupsFolderForApp(si, True, configSettings.FileShareRootFolder, si.AppToken.AppName), "Everyone")
Dim fileName As String = "SampleDataConnector.txt"
Dim fileFullPath As String = String.Join("\", fullPath, fileName)
Dim dt As New DataTable()
' Check file Exists
If File.Exists(fileFullPath) Then
' Declare TextFieldParser to handle line breaks in source file
Using parser As New TextFieldParser(fileFullPath)
' Set delimiter
parser.Delimiters = New String() {";"}
' Read the first line as header row
Dim headers As String() = parser.ReadFields()
' Loop on headers array
For Each header As String In headers
' Define columns
dt.Columns.Add(header)
Next
' Loop until end of file
While Not parser.EndOfData
' Read the current line as fields
Dim fields As String() = parser.ReadFields()
' Declare target dataRow
Dim dr As DataRow = dt.NewRow()
' Loop through CSV content
For i As Integer = 0 To headers.Length - 1
' Assign fields to dataRow
dr(i) = fields(i)
Next
' Add dataRow to dataTable
dt.Rows.Add(dr)
End While
End Using
End If
Related Content
- 8 months ago
- 2 years ago
- 11 months ago