11-12-2022
12:45 AM
- last edited on
05-02-2023
10:27 AM
by
JackLacava
Got a task to copy certain file from FileShare to Documents\Public because users security settings. Wanted to go with the standard System.IO.File.Copy(strSourceFile,strTargetFile) where source and targets are sting.
Can get full source file path using the FileShareFolderHelper. However can't get full path to the target, that is under FileSystemLocation.ApplicationDatabase.
Any suggestions how can I get the target path or otherwise copy the file in question?
Solved! Go to Solution.
11-14-2022 02:33 PM
The methods you need are under BRApi.Filesystem:
Here's a mock example that just copies a file from a user's document folder and changes the name. You'll need to swap the sourceFile/sourceDir pieces with FileShare pieces from BRApi.FileSystem.GetFileShareFolder according to your needs.
'Source file
Dim sourceFile As String = "SomeCSV.csv"
Dim sourceDir As String = $"Documents/Users/{StringHelper.RemoveInvalidNameCharacters(si.UserName,False,False)}"
'Target File
Dim targetFile As String = "CopiedFile.csv"
Dim targetDir As String = sourceDir
'Get the file
Dim sourceXFFileEx As New XFFileEx
sourceXFFileEx = BRApi.FileSystem.GetFile(si, FileSystemLocation.ApplicationDatabase, sourceDir & "/" & sourceFile,True,True)
'Save the file
Dim targetFileDataInfo As New XFFileInfo(FileSystemLocation.ApplicationDatabase, targetFile, targetDir)
Dim targetFileData As New XFFile(targetFileDataInfo, String.Empty, sourceXFFileEx.XFFile.ContentFileBytes)
BRApi.FileSystem.InsertOrUpdateFile(si, targetFileData)
11-14-2022 04:57 AM
Hi Koemets,
Would this be useful to get the full path to the target directory ?
'Folder to Create
Dim newPath As String = "Consolidation" '<-- This is the destination folder
Dim parentPath As String = "Documents/Public" '<-- App Folder path where new folder will be added, may be updated
'Get full folder path to test
Dim folderPath As XFFolderEx = BRApi.FileSystem.GetFolder(si, FileSystemLocation.ApplicationDatabase, parentPath & "/" & newPath)
'Create Folder if it does not exist
If folderPath Is Nothing Then
BRApi.FileSystem.CreateFullFolderPathIfNecessary(si, FileSystemLocation.ApplicationDatabase, parentPath, newPath)
End If
'Target Directory
Dim targetDir As String = BRApi.FileSystem.GetFolder(si, FileSystemLocation.ApplicationDatabase, parentPath & "/" & newPath).XFFolder.FullName
11-14-2022 09:35 AM
Unfortunately not 😞
OS object doesn't seem to have a method to copy the files, and standard IO needs full path. Meaning the /consolidation folder is being created by OS Framework which still doesn't return the full path, necessary to copy the file by the IO.
11-14-2022 01:31 PM
interesting. if you submit a ticket to support, please post the results.
11-14-2022 02:33 PM
The methods you need are under BRApi.Filesystem:
Here's a mock example that just copies a file from a user's document folder and changes the name. You'll need to swap the sourceFile/sourceDir pieces with FileShare pieces from BRApi.FileSystem.GetFileShareFolder according to your needs.
'Source file
Dim sourceFile As String = "SomeCSV.csv"
Dim sourceDir As String = $"Documents/Users/{StringHelper.RemoveInvalidNameCharacters(si.UserName,False,False)}"
'Target File
Dim targetFile As String = "CopiedFile.csv"
Dim targetDir As String = sourceDir
'Get the file
Dim sourceXFFileEx As New XFFileEx
sourceXFFileEx = BRApi.FileSystem.GetFile(si, FileSystemLocation.ApplicationDatabase, sourceDir & "/" & sourceFile,True,True)
'Save the file
Dim targetFileDataInfo As New XFFileInfo(FileSystemLocation.ApplicationDatabase, targetFile, targetDir)
Dim targetFileData As New XFFile(targetFileDataInfo, String.Empty, sourceXFFileEx.XFFile.ContentFileBytes)
BRApi.FileSystem.InsertOrUpdateFile(si, targetFileData)
11-14-2022 10:38 PM
Thank you. With minor corrections this worked. For the record (and future reference to whoever will search for it), FileShare root is located at
sourceXFFileEx = BRApi.FileSystem.GetFile(si, FileSystemLocation.FileShare, sourceDir & "/" & sourceFile,True,True)
Thank you for the solution!
3 weeks ago - last edited 3 weeks ago
Set the target folder as the public folder in the Application Database/Documents path
with the following:
Dim targetDir As String = $"Documents/Public"
Set the target path the same way, but now it will point to the public folder instead of the user's private folder:
Dim targetFileDataInfo As New XFFileInfo(FileSystemLocation.ApplicationDatabase, targetFile, targetDir)