Save Document ConnectionType to file example

Save Document ConnectionType to file example

avatar

Hello,

is there any example how to save document to disk from connection which has ConnectionType=Document ?

I tried something, but it is not working at all.
I will appreciate any help.

Thank you.

Ivo

All Comments (3)

avatar

Hello,

For being able to extract and save the document, we have to save the information in a variable and write the bytes in a file.

Here is a sample on how to extract a file saved in the database of a Document entry type.

$path = "C:\temp"
$session = Get-RDMSession -Name "MyDocument"
$fileName = $session.Document.Filename
$destination = Join-Path $path "\$fileName"
$fileInBytes = $session.data
[io.file]::WriteAllBytes($destination, $fileInBytes)


Let me know if that works.

Best regards,

Érica Poirier

avatar

Hello,

yes, it works (with two little tweaking)

$path="C:\temp"
$session = Get-RDMSession -IncludeDocumentsStoredInDatabase
$fileName = $session.Document.Filename
$destination = Join-Path $path "\$fileName"
$fileInBytes = $session.DocumentData
[io.file]::WriteAllBytes($destination, $fileInBytes)


Many thanks.

Best regards,
Ivo

avatar

Hello,

Thank you for your feedback and the tweaks!

It is also possible to use the Get-RDMSessionDocumentStoredInDatabase cmdlet which will return a list of sessions that contains document stored in the database.

Best regards,

Érica Poirier