Opening BLOB from DB as Attachment
Background
· I'm storing attachments in a Binary Large Object (BLOB) field in a table in a database.
· I also store the MimeType.
· I want to open them.
· I list the attachments for the user to peruse, with a HyperLink under the name.
· The hyperlink opens a new blank window and redirects to a blank ASPX page.
· I also pass the Attachment ID to the new page.
· The ASPX page has a Page_Load event.
· The Page_Load event gets the record and Binary Writes the byte() to the Response.
· Also, I envisage that if it was a spreadsheet, I want to launch Excel.
Problem Description
· This works for JPG.
· But didn't work for a text file.
· I haven't tried PDF yet, for instance and the text file I chose was a .reg file so that might not have been a wise test!
· First I get a debug window
· Second the browser says 'The XML page cannot be displayed'
· 'Invalid at the top level of the document'
Problem Resolution
· Me.Response.AddHeader('Content-Disposition', 'inline;filename=' & fileName)
· Now the browser asks if I want to run or save the .reg file.
· I must specify the filename, even though I’m not loading the response from an actual file (but from a Memory Stream).
· This works for XLS, PDF, and JPG.
· I haven’t tried ZIP yet.
Read More
No comments:
Post a Comment