05-03-2023 04:53 AM - last edited on 05-03-2023 12:03 PM by JackLacava
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?
Solved! Go to Solution.
05-03-2023 05:39 AM
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
05-03-2023 05:39 AM
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
05-04-2023 03:31 AM - edited 05-04-2023 03:31 AM
Hi OS_Pizza,
Does this require me to import any Namespaces? I tried adding the above to my existing Extender rule but it said that SessionOptions was not defined.
Many thanks
05-04-2023 03:37 AM
Absolutely ! Forgot to mention
Imports WinSCP
05-05-2023 01:53 PM - edited 05-05-2023 01:56 PM
@BenStuart If the shared drive is mapped to a local drive letter on the server where OS is running, you write directly to it like this:
File.WriteAllBytes("Z:\OneStreamShare\FileShare\data.csv", System.Text.Encoding.Default.GetBytes(csv.ToString()))