Skip to main content
Newcomer
Mar 1, 2024 10:29 PM UTC
Solved

Move file from File Explorer to File Share

I need to create a business rule that will move a file from a user's folder in File Explorer to the server's File Share. I am using the BRApi.FileSystem.GetFile method to successfully read the file, but I am unable to write the file to the server. I believe my issue is with the XFFileInfo parameters. I am not sure how many parameters to provide and what the value to provide for the folderFullName parameter. Here is my current code:

'Get the file
Dim sourceXFFileEx As New XFFileEx
sourceXFFileEx = BRApi.FileSystem.GetFile(si, FileSystemLocation.ApplicationDatabase, sourceDir & "/" & sourceFile,True,True)
												
'Save the file but this part is not working	 
Dim targetFileDataInfo As New XFFileInfo(FileSystemLocation.FileShare, fileName, ??)
Dim targetFileData As New XFFile(targetFileDataInfo, String.Empty, sourceXFFileEx.XFFile.ContentFileBytes)
BRApi.FileSystem.InsertOrUpdateFile(si, targetFileData)

 

Contributor
Mar 4, 2024 6:27 AM UTC

Hi Jrodgers,

You can try the follwoing apprach to move the file from the user's public directory to File Share > applications > Groups > Everyone directory. I hope this is what you're looking for.

'Get the file
Dim sourceXFFileEx As New XFFileEx
Dim sourceDir As String = "Documents/Users/" & si.UserName.Replace(" ","")
Dim sourceFile As String = "test_move.txt"
sourceXFFileEx = BRApi.FileSystem.GetFile(si, FileSystemLocation.ApplicationDatabase, sourceDir & "/" & sourceFile,True,True)

'Save the file but this part is not working  

Dim tgt = brapi.FileSystem.GetFolder(si, FileSystemLocation.FileShare, "Applications/"& si.AppName.Replace(" ", String.Empty) & "\Groups\Everyone\").XFFolder.ParentFullName
Dim targetFileDataInfo As New XFFileInfo(FileSystemLocation.FileShare, sourceFile, tgt )
Dim targetFileData As New XFFile(targetFileDataInfo, String.Empty, sourceXFFileEx.XFFile.ContentFileBytes)
BRApi.FileSystem.InsertOrUpdateFile(si, targetFileData)

 

4 replies

Contributor
Mar 4, 2024 6:27 AM UTC

Hi Jrodgers,

You can try the follwoing apprach to move the file from the user's public directory to File Share > applications > Groups > Everyone directory. I hope this is what you're looking for.

'Get the file
Dim sourceXFFileEx As New XFFileEx
Dim sourceDir As String = "Documents/Users/" & si.UserName.Replace(" ","")
Dim sourceFile As String = "test_move.txt"
sourceXFFileEx = BRApi.FileSystem.GetFile(si, FileSystemLocation.ApplicationDatabase, sourceDir & "/" & sourceFile,True,True)

'Save the file but this part is not working  

Dim tgt = brapi.FileSystem.GetFolder(si, FileSystemLocation.FileShare, "Applications/"& si.AppName.Replace(" ", String.Empty) & "\Groups\Everyone\").XFFolder.ParentFullName
Dim targetFileDataInfo As New XFFileInfo(FileSystemLocation.FileShare, sourceFile, tgt )
Dim targetFileData As New XFFile(targetFileDataInfo, String.Empty, sourceXFFileEx.XFFile.ContentFileBytes)
BRApi.FileSystem.InsertOrUpdateFile(si, targetFileData)

 

Employee - Sage
Mar 4, 2024 9:23 AM UTC

One thing people often don't realize, is that most OneStream classes are actually documented in the automatically-generated helper tree - but they might be a couple of level deeper than the starting tree.

In this case, we will pull up InsertOrUpdateFile from the tree. Because its definition includes custom OneStream-specific classes, if we click on the Objects tab, we will get such classes listed - but those are hyperlinks!

JackLacava_0-1709543770837.png

If you click on XFFile, you get the full documentation on that class, including all its constructors and methods. Here we see there is a FileInfo property, and again we can look in the Objects tab...

JackLacava_2-1709543936785.png

... and clicking on the hyperlink gives us all the goods on XFFileInfo, including a fairly straightforward constructor:

JackLacava_3-1709544011206.png

This technique should be enough to look up details for 80-90% of OneStream objects. Don't expect much descriptive text (although you will find occasionally find some, in the Definition tab), but the names are usually fairly explanatory.

I hope that helps!

Newcomer
Oct 27, 2024 4:05 PM UTC

Hi

Need some help please. My requirement is opposite, i want to move the file from File Share to File Explorer. Based on above response i created a extender BR as below. I am trying to move the file From Application/ApplicationName/DM/Export/Username To File Folder Documents//Public/Reports_Books.

when i am running the script i get this message -  1) Business Rule execution failed. Unable to load class 'OneStream.BusinessRule.Extender.SGA_FIle_Move.MainClass'.

===============================================================================================

Namespace OneStream.BusinessRule.Extender.SGA_File_Move
Public Class MainClass
Public Function Main(ByVal si As SessionInfo, ByVal globals As BRGlobals, ByVal api As Object, ByVal args As ExtenderArgs) As Object
Try
Select Case args.FunctionType
 
Case Is = ExtenderFunctionType.ExecuteDataMgmtBusinessRuleStep
'Get the file
Dim sourceXFFileEx As New XFFileEx
Dim sourceDir = brapi.FileSystem.GetFolder(si, FileSystemLocation.FileShare, "Applications/"& si.AppName.Replace(" ", String.Empty) & "\DataManagement\SandeepSingh\").XFFolder.ParentFullName
Dim sourceFile As String = "SGAData.csv"
sourceXFFileEx = BRApi.FileSystem.GetFile(si, FileSystemLocation.ApplicationDatabase, sourceDir & "/" & sourceFile,True,True)
 
'Save the file but this part is not working  
'Dim tgt = brapi.FileSystem.GetFolder(si, FileSystemLocation.FileShare, "Applications/"& si.AppName.Replace(" ", String.Empty) & "\Groups\Everyone\").XFFolder.ParentFullName
Dim tgt As String = "Documents//Public/Reports_Books/"
Dim targetFileDataInfo As New XFFileInfo(FileSystemLocation.FileShare, sourceFile, tgt )
Dim targetFileData As New XFFile(targetFileDataInfo, String.Empty, sourceXFFileEx.XFFile.ContentFileBytes)
BRApi.FileSystem.InsertOrUpdateFile(si, targetFileData)
 
 
End Select
 
Return Nothing
Catch ex As Exception
Throw ErrorHandler.LogWrite(si, New XFException(si, ex))
End Try
End Function
End Class
End Namespace
===================================================================================================
Employee - Guide
Oct 28, 2024 11:08 AM UTC

That error message sounds like a more fundamental issue to the business rule - is "SGA_FIle_Move" the name of the business rule?