Move File from Application Database to External Shared Drive

BenStuart
New Contributor III

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?

1 ACCEPTED SOLUTION

OS_Pizza
Contributor III

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

View solution in original post

4 REPLIES 4

OS_Pizza
Contributor III

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

BenStuart
New Contributor III

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

Absolutely ! Forgot to mention

Imports WinSCP

RobbSalzmann
Valued Contributor

@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()))