Dmitri Popov wrote:
Hi Drew,I'd be grateful, if you could also help me to write a macro that saves a file stored in the field into a directory specified by the user.
Hello Dimitri, OK - But firstI said that the earlier example had a flaw in that it did not update the UI properly. So ....Attached is a new version of the example database, one table, one form. Two buttons on the form, one to add a file into the database and one to write it out to disk.
The new routines have: No embedded SQL UI data aware controls are updated properly Database engine independence One comment about onClickWriteFile:No checking if the file already exists (meaning that it will overwrite any existing file's data ), consider yourself warned.
sub onClickAddFile( oEv as object ) dim oDataForm as object
dim FileName_w_Path as string dim inputStream as variant dim oBinaryField as object dim oFileNameField as object dim oFileSelection as objectGlobalScope.basicLibraries.LoadLibrary("Tools")
oDataForm = oEv.Source.Model.Parent
oBinaryField = oDataForm.Columns.GetByName( "FileObj" )
oFileNameField = oDataForm.Columns.GetByName( "FileName" )
oFileSelection = oDataForm.getByName("FileSelection")
if oFileSelection.Text <> "" then
FileName_w_Path = oFileSelection.Text
inputStream = fnOpenInputStream( FileName_w_Path )
oBinaryField.updateBinaryStream( inputStream,
InputStream.getInputStream.length )
oFileNameField.updateString( FileNameoutofPath( FileName_w_Path ) )
if oDataForm.isNew then
oDataForm.InsertRow
else
oDataForm.UpdateRow
end if
oFileSelection.Text = ""
end if
end sub
sub onClickWriteFile( oEv as object ) dim oDataForm as variant dim cFolder as string dim FileName_w_Path as string dim oBinaryField as variant dim oFileNameField as variant dim oSFA as objectoDataForm = oEv.Source.Model.Parent
oBinaryField = oDataForm.Columns.GetByName( "FileObj" )
oFileNameField = oDataForm.Columns.GetByName( "FileName" )
if PickFolder( cFolder ) = 1 then
if right( cFolder, 1 ) <> "/" then
FileName_w_Path = cFolder & "/" & oFileNameField.getString
else
FileName_w_Path = cFolder & oFileNameField.getString
end if
oSFA = createUNOService ("com.sun.star.ucb.SimpleFileAccess")
oSFA.WriteFile( ConvertToUrl(FileName_w_Path), oBinaryField.getBinaryStream ) end ifend sub
HTH Drew
storefile_datacontrols.odb
Description: application/vnd.sun.xml.base
--------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
