Loading...

Profitbase.IO.FileStorage

Profitbase.IO.FileStorage allows for accessing and processing of files stored in an Invision File Storage.


[byte[]] $fileContent = [Profitbase.IO.FileStorage]::ReadAllBytes($storageName, $fileName)

Returns a file (as byte array) given by name of an Invision File Storage and a file name.


[byte[]] $fileContent = [Profitbase.IO.FileStorage]::ReadAllBytesByReferenceId($fileReferenceId)

Returns a file (as byte array) given by file reference.


[Profitbase.IO.FileStorage]::DeleteFile($storageName, $fileName)

Deletes a file given by name of a Invision File Storage and a file name.


[Profitbase.IO.FileStorage]:: DeleteFileByReferenceId ($fileReferenceId)

Deletes a file given by a a file reference.


[string[]] $fileNames = [Profitbase.IO.FileStorage]::GetFileNames($storageName [,$contextQuery [,$mimeTye]] )

Returns a list of files. This list can optionally be filtered by a Context Query and Mime Type. The Context Query is based on Context keys defined in the File Storage and has a format like i.e.

DepartmentID==Avdeling2 && EmployeeId==123 && DepartmentSize==200

[Profitbase.IO.FSFileInfo[]] $fileInfos = [Profitbase.IO.FileStorage]::GetFileInfos($storageName [,$contextQuery [,$mimeTye]] )

Returns a list of file information. This list can optionally be filtered by a Context Query and Mime Type. The records in the result contains fields for: FileName, ContextJson, MimeType, FileReferenceId, CreatedBy, Created, LastChangedBy and LastChanged.


Examples:

Read a Powershell script from the given file in the storage, and execute it.

param (
[ Parameter ( Mandatory = $TRUE )][string] $storageName,
[ Parameter ( Mandatory = $TRUE )][string] $fileName
)
[byte[]] $result = [Profitbase.IO.FileStorage]::ReadAllBytes($storageName, $fileName)
$enc=[System.Text.Encoding]::UTF8
$code=$enc.GetString($result)
Invoke-Expression $code

List file by a query.

param (
[ Parameter ( Mandatory = $TRUE )][string] $storageName,
[ Parameter ( Mandatory = $FALSE )][string] $contextQuery,
[ Parameter ( Mandatory = $FALSE )][string] $mimeType
)
[string[]] $result = [Profitbase.IO.FileStorage]::GetFileNames($storageName, $contextQuery, $mimeType)
Write-output $result