New Zealand's new Copyright Law presumes 'Guilt Upon Accusation' and will Cut Off Internet Connections without a trial. CreativeFreedom.org.nz is against this unjust law - help us


A Space for All Things .NET Related


Opening BLOB from DB as Attachment

By James Hippolite, in , posted: 19-Sep-2008 11:26

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.

 

 

Other related posts:
Geek Post Monthly Newsletter Volume 2 Issue 6
Exam 70-300 Objective 3
COALESCE T-SQL Function






Add a comment

Please note: comments that are inappropriate or promotional in nature will be deleted. E-mail addresses are not displayed, but you must enter a valid e-mail address to confirm your comments.

Are you a registered Geekzone user? Login to have the fields below automatically filled in for you and to enable links in comments. If you have (or qualify to have) a Geekzone Blog then your comment will be automatically confirmed and shown in this blog post.

Your name:

Your e-mail:

Your webpage:

JamesHip's profile

James Hippolite
Wellington
New Zealand


Welcome to my technical blog. 

Here, I attempt to distill the Microsoft Certified Professional Developer knowledge I have accumulated since first qualifying MCP in 1996.  This blog started on 13 September 2007 as an off-shoot from my mixed up personal blog.  But it took a shot in the arm from Scott Hanselman's talk at TechEd New Zealand 08 "32 Ways To Make Your Blog Suck Less".