Friday, September 19, 2008

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.

Wellington Workgroup Solutions Team

P1000002 P1000004
James Hippolite, Senior .NET Developer Martin Harris, .NET Developer
P1000005 Gary Saunders
Megha Barpande, .NET Developer Gary Saunders, Lead Developer

Sunday, September 14, 2008

James went to Tech Ed 08

IMAG0015 IMAG0016
Tech-Ed panel discussion. Scott Hanselman on the floor. Wider shot. Chris Auld of Intergen is facilitating this discussion.  In my personal opinion, it's the best job Chris has demonstrated in all the years I've observed him on stage.
IMAG0017 IMAG0018
Four of the eight members of the Workgroup Solutions Team were at Tech Ed this year.  We are Telecom's only internally-focused .NET development team (our externally-focused team is called Gen-i). 

The WST belongs to Applications Development, Maintenance and Support, a part of Technology & Shared Services.
Gary Saunders, Team Leader of Wellington.
IMAG0019 IMAG0022
David Bulog, DBA of Auckland Norman Close, Senior Developer of Christchurch

Wednesday, September 10, 2008

SubSonic Workaround

SubSonic is an Object Relational Mapper (ORM) tool to which I converted a few months back from Strongly-Typed Datasets in Visual Studio.  SubSonic is a free open source program.  It’s brilliant because you point it at your database (supplying the database connection string) and it generates the code that maps your tables into classes.  It automatically generates your Data Access Layer for you.  Anytime you need to alter a table structure, you merely re-run SubSonic, et voila, your classes instantly reflect the change.  You don’t need to muck around with editing 4 stored procedures like I used to do with Strongly Typed Datasets.

As long as the User ID you specified in your connection string has SELECT rights on your table(s) and/or EXEC rights on your Stored Procedures, then SubSonic will pick that up and make only those objects available.  If you want your application to do INSERTS, you also need to grant that right to your User, and SubSonic will auto-generate a method for Insert.

However, I’ve recently discovered a bug, and subsequently the workaround for it.

Problem Description

You can call a stored procedure with the following code:

Public Function GetOutstandingRequests() As DAL.RequestCollection

Dim sp1 As StoredProcedure
Dim ds1 As DataSet
Dim dt1 As DataTable
Dim retVal As New DAL.RequestCollection

sp1 = DAL.SPs.SelectRequestsByFilter()
ds1 = sp1.GetDataSet()
dt1 = ds1.Tables(0)
retVal.Load(dt1)

Return retVal
End Function

This will result in an error: Object does not exist on the line that attempts to GetDataSet().

Explanation

The bug is that SubSonic cannot instantiate a stored procedure that doesn’t have any parameters.

Workaround

The workaround is to alter your Stored Procedure to always accept at least one parameter and use them to instantiate the object, thus:

Public Function GetOutstandingRequests(ByVal createdBy As String, ByVal responseTypeID As Integer?, ByVal seekerID As Integer?) As DAL.RequestCollection
Dim sp1 As StoredProcedure
Dim ds1 As DataSet
Dim dt1 As DataTable
Dim retVal As New DAL.RequestCollection

sp1 = DAL.SPs.SelectRequestsByFilter(createdBy, responseTypeID, seekerID)
ds1 = sp1.GetDataSet()
dt1 = ds1.Tables(0)
retVal.Load(dt1)

Return retVal
End Function

Status

If anyone is aware of whether this issue will be fixed in future versions of SubSonic, I’d be grateful to be kept informed (I’m using version 2.1 [Final] at present).  Please leave a comment or send me a tweet.

Tuesday, September 2, 2008

#tenz8 Notes from the Field at NZ Tech-Ed 08 day 3

When Where What
03-09-2008 7:00 Hotel Good morning Lord (at least it's better than "good lord, it's morning!") 5.5 hours sleep not enough
03-09-2008 9:00 WEB309 Jonas on Silverlight
03-09-2008 9:45 WEB309 in Silverlight, all networking is asynchronous
03-09-2008 10:00 WEB309 if (HtmlPage.IsEnabled) useDB else useStub;
03-09-2008 10:15 WEB309 having just seen it quickly demoed, I finally understand MembersipProvider
03-09-2008 10:45 SEC201 largest room is packed for Steve Riley
03-09-2008 11:15 SEC201 steve showed Bush-Blair-Love-Duet. laf!
03-09-2008 11:30 SEC201 steve is an Evolutionist. I am not.
03-09-2008 11:45 SEC201 risk = threat (severity) x vulnerability (1 or 0) x exposure (dollars)
03-09-2008 12:00 SEC201 great stuff, good entertainer, raving liberal
03-09-2008 12:10 Lab bin05 lab authoring ms sql reports
03-09-2008 13:00 Lab i feel it's time (when the refresh laptop arrives next week) to install sql08 and vs sp1
03-09-2008 13:25 Lunch @freitasm informed me my 2 posts from the field were too big!
03-09-2008 14:30 DAT355 fixed posts but missed first half of Greg Lows talk
03-09-2008 14:45 DAT355 anybody sticking around for dinner tonight?
03-09-2008 15:00 DAT355 Greg is usually better than this but: death by PowerPoint
03-09-2008 15:15 DAT355 presenters: PP is for agendas, not white-papers
03-09-2008 15:30 DAT355 funniest presenter comment (which is also true for me) "I have no inner dialogue"
03-09-2008 15:35 Tea see you Owen. Wellington represent!
03-09-2008 16:00 DEV486 MindScape on da stage. Wellington represent!
03-09-2008 16:30 DEV486 hey! c# has #if debug. VB had that how long?
03-09-2008 17:00 DEV486 extension methods will be useful
03-09-2008 18:00 Drinkies Monsoon Poon 7pm (go dutch)

#tenz8 Notes from the Field at NZ Tech-Ed 08 day 2

Time Where Comments
02-09-2008 8:30 Breakfast great conversations
02-09-2008 9:00 BIN309 changed my mind, from ARC to SQL
02-09-2008 9:10 BIN309 is it just me, or does Pat Martin remind anybody else of Malcolm McDowell?
02-09-2008 9:20 BIN309 this class is full
02-09-2008 9:30 BIN309 merge statement is very verbose
02-09-2008 9:45 BIN309 death by PowerPoint
02-09-2008 10:00 BIN309 super dump! should I shout skull ?
02-09-2008 10:45 WEB304 web future starting. @kiwitwitter is in it
02-09-2008 10:50 WEB304 each country thinks broadband speed is better elsewhere
02-09-2008 11:00 WEB304 contrary to all appearances Scottha is not really a Budhist
02-09-2008 11:15 WEB304 reach out and Touch some device
02-09-2008 11:30 WEB304 finally Chris Auld has found his niche: he's a hopeless panelist but a great convenor
02-09-2008 11:45 WEB304 "Silverlight gets us around the limitations of HTML, is the future of the web"
02-09-2008 12:00 WEB304 just realised: unlike 2005, have no time for labs, too many good sessions
02-09-2008 12:10 DEV260 TFS version control starting
02-09-2008 12:30 DEV260 @kiwitwitter it was fun thanks
02-09-2008 13:00 DEV260 death by PowerPoint
02-09-2008 13:25 DEV260 multiple forward integration for each reverse integration
02-09-2008 13:40 Lunch listening to Trika talk about certification
02-09-2008 15:00 LAB doing labs
02-09-2008 15:30 LAB trika was lovely and gracious
02-09-2008 16:00 LAB missed 2 sessions 2 do 1 MVC lab. glad i did but MVC not 4 me
02-09-2008 16:30 LAB im loving sub sonic too much to MVC
02-09-2008 17:00 LAB just did another lab: Test Management
02-09-2008 17:10 WEB317 ASP.NET AJAX SP1 starting
02-09-2008 18:20 WEB317 ScriptManager EnableHistory=true
02-09-2008 18:25 WEB317 @blackmael MVC seems 2 be 3-tier on the presentation layer. y bother?
02-09-2008 20:15 Tech-Fest idea 4 next year: have a dinner on Tuesday for those not inclined to booze
02-09-2008 20:20 Tech-Fest great idea Intergen: earplugs in survival kit
02-09-2008 20:25 Tech-Fest takeaways 4 dinner, heading back to hotel
02-09-2008 20:30 Tech-Fest latte anyone?
02-09-2008 23:00 Hotel Completed compiling Tweats into Blog Post

Monday, September 1, 2008

#tenz8 Notes from the Field at NZ Tech-Ed 08 day 1

Time

Where Comments
01-09-2008 8:27 Plenary in plenary session
01-09-2008 8:53 Plenary listening to John Key
01-09-2008 8:54 Plenary disintermediate?
01-09-2008 9:03 Plenary NZ is an under-performing company. change the management
01-09-2008 9:05 Plenary meaningless Global Warming dribble from Labour
01-09-2008 9:13 Plenary 2000 IT pros here now
01-09-2008 9:25 Plenary Live Mesh = software + services
01-09-2008 9:27 Plenary Google = software as a service
01-09-2008 10:44 WEB301 Scott Hanselman starting
01-09-2008 12:10 WEB301 MVC routing as user interface
01-09-2008 12:13 DEV215 Windows Mobile development started
01-09-2008 12:40 DEV215 great demo query webservice and create calendar item
01-09-2008 13:00 DEV215 Silverlight 4 Mobile is immanent
01-09-2008 14:24 SOA301 how to AJAX enable WCF services
01-09-2008 15:10 SOA301 ctrl+k+v = auto-format
01-09-2008 15:19 SOA301 register web service inside ScriptManager
01-09-2008 15:53 WEB302 when scottha mentions poo shout skull
01-09-2008 16:27 WEB302 scottha is demo-ing Linq 2 REST
01-09-2008 16:53 WEB302 big ups from scottha to Ivan Towlson. prestige!
01-09-2008 17:05 WEB302 Scott Hanselman's The Man!
01-09-2008 17:15 DEV335 VB2008 Starts
01-09-2008 18:15 DEV335 i cannot conceive of any use for anonymous delegates
01-09-2008 18:30 DEV335 Nick Randolph Speaks My Language
01-09-2008 20:00 Dinner bloggers dinner starts
01-09-2008 20:08 Dinner just discovered none of my tenz8 tweats were logged!
01-09-2008 22:08 Dinner scottha talks 32 ways 2 make blog suck less
01-09-2008 23:00 Bar Plenty of social networking opportunities.  A great forum.
01-09-2008 23:30 Bar I might have volunteered to assist Mauricio with his GeekZone DB issues?!?!?!