How to save attachments from the WEBCON BPS form to a hard drive or network share.
This post was inspired by an article found on the web “Export Documents saved as Blob / Binary from SQL Server“. The article shows how to use the T-SQL language to save a file stored in the database on the hard disk. Let’s use this knowledge in our WEBCON BPS environment.
Enabling Ole Automation Procedures
First of all, to enable file export you must enable the “Ole Automation Procedures” option. To do this, run the script below. Note – the option is disabled by default for security reasons. Make sure its inclusion can be done in your company.
Procedure for exporting attachments
Below there is a T-SQL script that allows you to export attachments with a specific ID from the WEBCON database. NOTE: In my example, the attachment database is in the WEBCON BPS content database. In your case, attachments may be in the attachment database or another dedicated attachment database. Verify where your files are stored before creating a routine.
NOTE: Remember that the implementation of unauthorized changes on the WEBCON database may result in the loss of the warranty!
Attachments export: WEBCON BPS process configuration
You need to add 2 actions to the transition path:
- Action that will return IDs of attachments to be exported. In my case, these will be all attachments from the current form.
- The standard “Run an SQL procedure” action that calls the SQL procedure which is used to save the file on the hard disk based on the SQL query.
Permissions for the IIS application pool account
The queries executed from WEBCON platform are run executed as IIS Application Pool account. In the procedure above, there are used procedures that are executed on the master database. It is therefore necessary to grant the account permissions to run them on dat database. Below is a script to grant the appropriate permissions. For me it is “ALTERPATHS\SP_WEB” account. In case you do not know which account to enter, see this article for information how to check which account is configured as an IIS application pool account.
How it works
Export: Limitations of the described solution
- The files must be saved to a folder that already exists. If you want to create an additional folder – see the article how to make stored procedure to create folders .
- If there are several files with the same name on the form, the previous file with he same name will be overwritten. If you want files not to be overwritten, you need to add this case handling in the T-SQL script.