In a prior post, I showed how to use BCP to extract and save Dynamics GP Document Attach files. I decided to explore this further and use .NET to extract the GP Doc Attach files.
It is very easy to export the file attachments from SQL using .NET, but because you need some data access commands to read the data from the VarBinary field and separate write the data to a file using a stream, it's quite a few more lines than the very simple single-line BCP statement.
This MSDN forum post has the basic code sample, which is 9 lines. So in theory you could have something that simple. But in reality any .NET application of value is going to have a fair amount of additional code for a data access layer and other plumbing, allowing for parameters, processing multiple records, error handling, etc.
To start, I have an ExecuteScalar data access method that returns a byte array.
Finally, I have a method that retrieves the list of attachments and calls the SaveAttachment method for each file. This is where you could have additional parameters and logic, like maximum number of files, filter by file extension, filter by GP record type, of filter by customer, vendor, etc.
This prototype code is relatively simple and works well, writing out my two sample attachments, a text file and a JPG.
So, if you have a .NET application or integration, or perhaps even a reporting platform that can utilize .NET, you could use this approach.
One consideration is that this sample writes the attachment to disk as a file. This would probably be less than ideal for a dynamically generated report, so I would look into whether it is possible to retrieve an in-memory representation of the image file and embed it in the report. I've never done anything like that, so I don't know if that is possible.
Anyway, that's a second method. If I have time, I'll see if I can use VBA in GP Report Writer to extract image files from Doc Attach and embed them on a report.