Can we merge 2 files using Business Rules
Hi,
I have a requirement to export 2 files and then merge it into single file. While the export can be done via OOTB DM step, I wonder if we have any api or default function which can be used to merge the 2 exported files?
I see, thanks! Just throwing in a suggestion here, since you will be using a business rule, why not creating a single export file right in that rule rather than relying on the DM steps to create two files first just to merge them later on?
aformenti and FredLucas provided some great snippets here:
Solved: Export data using a Method Query - OneStream Community (onestreamsoftware.com)
Sure, no problem.
Following some Api's examples on how to get/manage application files/folders:
' Declare stringbuilder Dim sb As New Text.StringBuilder ' Get FolderName Dim folderFullName As String = BRApi.FileSystem.GetFolder(si, FileSystemLocation.ApplicationDatabase, Path.Combine("Documents/Users", StringHelper.RemoveWhiteSpace(si.UserName))).XFFolder.FullName ' Get All Files In folder Dim contentFileExtensionFilters As New List(Of String)({"csv","txt"}) Dim objList As List(Of XFFileInfoEx) = BRApi.FileSystem.GetFilesInFolder(si, FileSystemLocation.ApplicationDatabase, folderFullName, XFFileType.All, contentFileExtensionFilters) objList.ForEach(Sub(lambda) sb.AppendLine(String.Format("objList -> {0}", lambda.XFFileInfo.FullName))) ' Create XFFolderEx Dim objXFFolderEx As XFFolderEx = BRApi.FileSystem.GetFolder(si, FileSystemLocation.ApplicationDatabase, folderFullName) sb.AppendLine(String.Format("XFFolder.FullName -> {0}", objXFFolderEx.XFFolder.FullName)) ' Get File Dim objXFFileEx As XFFileEx = BRApi.FileSystem.GetFile(si, FileSystemLocation.ApplicationDatabase, String.Format("{0}/{1}", folderFullName, "Test.csv"), True, True) sb.AppendLine(String.Format("XFFile.ContentFileBytes.Length -> {0}", objXFFileEx.XFFile.ContentFileBytes.Length)) ' Retrieve File As Bytes() Dim fileBytes As Byte() = objXFFileEx.XFFile.ContentFileBytes() 'Connect to Application DB Using dbConnApp As DBConnInfo = BRApi.Database.CreateApplicationDbConnInfo(si) Dim dbFileInfo As New XFFileInfo(FileSystemLocation.ApplicationDatabase, "TestNew.csv", folderFullName, XFFileType.Unknown) dbFileInfo.ContentFileContainsData = True dbFileInfo.ContentFileExtension = dbFileInfo.Extension Dim dbFile As New XFFile(dbFileInfo, String.Empty, fileBytes) ' Insert File BRApi.FileSystem.InsertOrUpdateFile(si, dbFile) End Using ' Log Result -> Throw Error Throw New XFException(Convert.ToString(sb))
Once you have the two files as byte(), you can do something like (I haven't tested this):
Dim bytesful() As Byte = bytes.Concat(bytescrc).ToArray()
Let me know if you have any problems, happy to assist further.
Best,
Albert