SRAI
3 years agoNew Contributor III
Importing a CSV file from from Documents/Public/xyz folder to OneStream Cube
Hi,
I have a requirement to import a Cell Details CSV file into OS. My questions are as below:
1. Can we import a CSV file from Documents/Public/xyz folder to OneStream Cube? I tried it but it didn't worked. However, I was able to import the CSV from File Share folder.
2. To achieve above, I was trying to copy the CSV file from Documents/Public/xyz folder to File Share folder but I am getting an error "Part of the path cannot be found" (SRC Path: Documents/Public/xyz folder).
Error:
Here is the code to copy a CSV file from Documents/Public/xyz folder to File Share folder:
If args.CustomCalculateArgs.FunctionName.XFEqualsIgnoreCase("Move_File_from_Public_to_FS_Folder")
Dim configSettings As AppServerConfigSettings = AppServerConfig.GetSettings(si)
Dim xfolderPath As String = FileShareFolderHelper.GetDataManagementExportUsernameFolderForApp( _
si,True, configsettings.fileShareRootFolder,si.AppToken.AppName)
Dim DestinationPath As String = "Cell_Details"
Dim ParentPath As String = "Documents/Public"
Dim fileToMove As String = "Cell_Details.csv"
Dim folderPath As String = BRApi.FileSystem.GetFolder( _
si, FileSystemLocation.ApplicationDatabase, ParentPath & "/" & DestinationPath).XFFolder.FullName
brapi.ErrorLog.LogMessage(si, "folderPath:" & folderPath)
'File.Copy(Path.Combine(folderPath & "/" & "Cell_Details.csv"), _
' Path.Combine(xfolderPath & "/" & "Cell_Details.csv"), True) <--- TRIED THIS COMMAND AS WELL BUT GOT THE SAME ERROR
Dim fileBytes As Byte() = File.ReadAllBytes(folderPath & "/" & fileToMove)
Using dbConnApp As DBConnInfo = BRApi.Database.CreateApplicationDbConnInfo(si)
Dim dbFileInfo As New XFFileInfo( _
FileSystemLocation.ApplicationDatabase, fileToMove, xfolderPath, XFFileType.Unknown)
dbFileInfo.ContentFileContainsData = True
dbFileInfo.ContentFileExtension = dbFileInfo.Extension
Dim dbFile As New XFFile(dbFileInfo, String.Empty, fileBytes)
BRApi.FileSystem.InsertOrUpdateFile(si, dbFile)
End Using
End If
Below code is working which copies CSV file from File Share folder to Public folder:
If args.CustomCalculateArgs.FunctionName.XFEqualsIgnoreCase("Move_File_from_FS_to_Public_Folder")
Dim configSettings As AppServerConfigSettings = AppServerConfig.GetSettings(si)
Dim xfolderPath As String = FileShareFolderHelper.GetDataManagementExportUsernameFolderForApp( _
si,True, configsettings.fileShareRootFolder,si.AppToken.AppName)
Dim DestinationPath As String = "Cell_Details"
Dim ParentPath As String = "Documents/Public"
Dim fileToMove As String = "Cell_Details.csv"
Dim fileBytes As Byte() = File.ReadAllBytes(xfolderPath & "/" & fileToMove)
Dim targetDir As String = BRApi.FileSystem.GetFolder(si, _
FileSystemLocation.ApplicationDatabase, ParentPath & "/" & DestinationPath).XFFolder.FullName
Using dbConnApp As DBConnInfo = BRApi.Database.CreateApplicationDbConnInfo(si)
Dim dbFileInfo As New XFFileInfo( _
FileSystemLocation.ApplicationDatabase, fileToMove, targetDir, XFFileType.Unknown)
dbFileInfo.ContentFileContainsData = True
dbFileInfo.ContentFileExtension = dbFileInfo.Extension
Dim dbFile As New XFFile(dbFileInfo, String.Empty, fileBytes)
BRApi.FileSystem.InsertOrUpdateFile(si, dbFile)
End Using
End If
Appreciate any help.
Thanks,
Sid
Try this
Dim fileName As String = "CellDetails.csv" Dim usrfile As XFFileEx = BRApi.FileSystem.GetFile(si, FileSystemLocation.ApplicationDatabase, "Documents/Public/" & fileName, True, True) Dim fileBytes As Byte() = usrfile.XFFile.ContentFileBytes File.WriteAllBytes($"{BRApi.Utilities.GetFileShareFolder(si, FileShareFolderTypes.ApplicationIncoming, Nothing).Replace("Incoming", "")}DataManagement\Export\{StringHelper.RemoveInvalidNameCharacters(si.UserName, False, False)}\{fileName}", fileBytes)