BenStuart
2 years agoNew Contributor III
Move File from Application Database to External Shared Drive
I currently have a metadata file being created by an Extender BR and saved down to the Application Database:
Case Is = ExtenderFunctionType.ExecuteDataMgmtBusinessRuleStep
'Export File
Dim fileName As String = "AccessoryMetadata.csv"
Dim filePath As String = $"Documents/Public/XFDocs/XFDocs_Public"
Dim ud1DimPk As DimPk = BRApi.Finance.Dim.GetDimPk(si, "MainProduct")
Dim category As String = ""
Dim businessStream As String = ""
'Export CSV to User Temp Folder
Dim listOfParents As List(Of memberinfo) = BRApi.Finance.Members.GetMembersUsingFilter(si, _
ud1DimPk, _
"U1#ReportingProduct.Descendants.Where(" & _
"Name Contains Accessories" & _
"And Name <> 15_Accessories" & _
"And HasChildren = True)", _
True)
Dim csv As New Text.StringBuilder
csv.AppendLine("Name, Description, ParentName, Category, Business Stream")
For Each parentMember In listOfParents
For Each childMember In BRApi.Finance.Members.GetChildren(si, _
ud1DimPk, parentMember.Member.MemberId)
...
csv.AppendLine($"""{childMember.Name}"",""{childMember.Description _
}"",""{parentMember.Member.Name}"",""{category}"",""{businessStream}""")
Next
Next
Dim fileBytes As Byte() = Encoding.UTF8.GetBytes(csv.ToString)
'Save csv to file
Dim XFfileDataInfo As New XFFileInfo(FileSystemLocation.ApplicationDatabase, fileName, filePath)
Dim XFfileData As New XFFile(XFFileDataInfo, String.Empty, fileBytes)
brapi.FileSystem.InsertOrUpdateFile(si, XFfileData)
Is there any way to then automatically move this file to an external shared drive? Or does the above need to be written in a different way in order for it to work?
You can move any file from onestream to external shared drive.
'1. Create your session here Dim sessionOptions As New SessionOptions With sessionOptions .Protocol = WinSCP.Protocol.Sftp .Portnumber = 22 .HostName = "" .UserName = "" .PrivateKeyPassphrase = "" .SshHostKeyFingerprint = "" .SshPrivateKeyPath = "" End With '2. Send file using the session FileName = "FileName.csv" Using session As New Session ' Connect session.Open(sessionOptions) Dim LocalDirectory As String = BRApi.FileSystem.GetFileShareFolder(si, FileShareFolderTypes.BatchHarvest, api) Dim Dest_folder As String ="" session.PutFiles(LocalDirectory & FileName, Dest_folder & FileName) End Using