cancel
Showing results for 
Search instead for 
Did you mean: 

Importing a CSV file from from Documents/Public/xyz folder to OneStream Cube

SRAI
New Contributor III

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).

SRAI_0-1642510815280.png

 

Error:

SRAI_1-1642510931428.png

 

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

1 ACCEPTED SOLUTION

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)

View solution in original post

2 REPLIES 2

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)

SRAI
New Contributor III

Thanks Celvin. It works. A lot to learn 🙂