Save BLOB in a file system Windows with #SYS_APPLN.CreateFileSaveDialog

This Q&A forum allows users to post and respond to "How Do I Do ....." questions. Please do not use to report (suspected) errors - you must use your regional help desk for this. The information contained in this forum has not been validated by LANSA and, as such, LANSA cannot guarantee the accuracy of the information.
Post Reply
dvanoni
Posts: 37
Joined: Wed Dec 02, 2015 3:47 am
Location: Chiasso - Switzerland

Save BLOB in a file system Windows with #SYS_APPLN.CreateFileSaveDialog

Post by dvanoni » Wed May 24, 2023 2:29 am

Hi everyone,

I must save a blob file read from a table and allow user to choose the destination folder in its file system. The application is a Windows application.

My code is similar to this one:

Code: Select all

Define_Com Class(#prim_Appl.ICommonDialogFileSave) Name(#SaveDialog) Reference(*dynamic)
Fetch Fields(#Blob_file) From_File(BLOB_file_table) With_Key(#BLOB_file_table_key)
#SaveDialog <= #SYS_APPLN.CreateFileSaveDialog
#SaveDialog.File := #Blob_file.FileName
If Cond(#SaveDialog.show)
endif
With this code I can show the save dialog, choose the folder in the file system but nothing happens when I press the Save button. The file exists because I can find it in the Lansa temp folder.

How can I make it work?

Thanks

User avatar
Dino
Posts: 359
Joined: Fri Jul 19, 2019 7:49 am
Location: Robbinsville, NC
Contact:

Re: Save BLOB in a file system Windows with #SYS_APPLN.CreateFileSaveDialog

Post by Dino » Wed May 24, 2023 3:58 am

Following the example xDemoFileSave (Form XDEMOF_9), I noticed that I can make it work if you have a button to Save in the screen, but not if you dont...
the actual error is this one:

Code: Select all

---------------------------
Fatal Error
---------------------------
Component : TEST5232
   createfilesavedialog
Statement : 24
Message : Windows error - stay on top forms require a main form.
Routine : File LpVoDlg at line 108.

---------------------------
OK   
---------------------------
but if you have a save button and call this routine from the click on the button, it works fine. No idea what is the reason behind it, but in this way, works fine.
Notice that the Dialog is just a dialog to select the folder and filename that you are going to use to save it. basically it returns to you a path with a filename. No storage of any kind is performed.

For the #FileSave.Show, you can do whatever you want to save the image. In this case, as is a blob field, when you access it in your program it will put the blob content in a file in a temporary directory inside your installation. If you want to move it to the location selected, use the OV_FILE_SERVICE to copy it from the temporary directory to the new location.

Code: Select all

Function Options(*DIRECT)
Begin_Com Role(*EXTENDS #PRIM_FORM) Theme(#SYS_THEME<2015Blue>) ClientWidth(551) ClientHeight(301) Left(612) Top(207) Width(567)

Define_Com Class(#PRIM_PHBN) Name(#Save) Caption('Save') DisplayPosition(1) Left(416) Parent(#COM_OWNER) TabPosition(1) Top(264) Width(129)

Evtroutine Handling(#Save.Click)
#Com_owner.Save
Endroutine

Mthroutine Name(Save)

Define_Com Class(#Prim_appl.ICommonDialogFileSave) Name(#FileSave) Reference(*DYNAMIC)

Fetch Fields(#xEmployeeImage) From_File(xEmployeeImages) With_Key(100066)
#FileSave <= #sys_appln.CreateFileSaveDialog
#FileSave.File := #xEmployeeImage.FileName

If (#FileSave.Show)
Use Builtin(OV_FILE_SERVICE) With_Args("COPY_FILE" #xEmployeeImage.FileName #FileSave.File) To_Get(#IO$STS)
Endif
Endroutine
End_Com

dvanoni
Posts: 37
Joined: Wed Dec 02, 2015 3:47 am
Location: Chiasso - Switzerland

Re: Save BLOB in a file system Windows with #SYS_APPLN.CreateFileSaveDialog

Post by dvanoni » Wed May 24, 2023 3:31 pm

Thanks a lot Dino!

It works!

Post Reply