Forum Discussion

Marco's avatar
Marco
Contributor II
2 years ago
Solved

Create CSV FILE

Hi Everyone.

I am creating a CSV file with the information from a datatable. The problem is that it generates the file with the columns but without the datatable information. I wanted to know if there is another way to create a CSV file correctly.

Dim strFilePathFull_AllocationDetails As String = strFilePath & "/" & strModelName & "_" & strScenarioName & "_" & strTimeName & "_" & dtAllocationDetails.TableName & ".csv"

Dim xfeFile_AllocationDetails As XFFileEx = dtbSH.DataTableToFile(si, dtAllocationDetails, strFilePathFull_AllocationDetails, Nothing)
And my function:
Public Function DataTableToFile(ByVal si As SessionInfo, ByVal dt As DataTable, ByVal strFilePath As String, ByVal listColToSkip As List(Of String), ByVal Optional strSeparator As String = ",") As XFFileEx
	Dim strDt As String = Me.PrintDataTable(si, dt, strSeparator, 0, False, listColToSkip, """")
	Dim bytes() As Byte = System.Text.Encoding.UTF8.GetBytes(strDt)
	Dim fileinfo As New XFFileInfo(fileSystemLocation.ApplicationDatabase, strFilePath)
	Dim xfFile As New XFFile(fileinfo, String.Empty, bytes)
	BRApi.FileSystem.InsertOrUpdateFile(si, xffile)
	Dim xfeFile As New XFFileEx(xffile, DataAccessLevel.AllAccess, False)
	Return xfeFile
End Function

 

5 Replies

    • Marco's avatar
      Marco
      Contributor II

      I had already seen the post, but that doesn't solve the problem of the row values not appearing, only the column values are displayed.

      • JackLacava's avatar
        JackLacava
        Community Manager

        If the file is created, and it contains something, then the code you posted has done its job.

        What has probably not done its job, is the "Me.PrintDataTable" function you have there. You might want to post the content of that function. To verify, you can write that strDt variable to errorlog to see what it actually contains.