I'm trying to download a file in the click event of a linkbutton. I've
got working code for this, however, the 'Open' function of the dialog
that pops up doesn't work. The 'Save' does, and I can successfully
open the file that was saved.
Here's my code:
------------------------------------------------------------------
Private Sub Document_Click(ByVal source As Object, ByVal args As
System.EventArgs) Handles lnkBtnDocument.Click
Dim oStreamReader As System.IO.StreamReader
'internal method to cast a SQL stored procedure parameter
Dim oParam As New
Common.DataAccess.SPParameter("@DOCUMENT_ID",
CInt(CStr(Me.GetFieldValue("DOCUMENT_ID", Nothing).Value)))
Dim ds As DataSet =
Common.DataAccess.DataAccessFunctions.Execute_Stor ed_Procedure("DOCUMENT_BINARY_GET",
oParam)
If Not ds.Tables.Count < 1 AndAlso Not
ds.Tables(0).Rows.Count < 1 Then
Dim byteField() As Byte =
CType(ds.Tables(0).Rows(0).Item("DOCUMENT"), Byte())
context.Response.Clear()
context.Response.AddHeader("Content-Disposition",
String.Format("attachment; filename={0}",
Replace(CStr(ds.Tables(0).Rows(0).Item("FILE_NAME" )), ".",
Now.ToFileTime.ToString & ".")))
context.Response.BinaryWrite(byteField)
Context.Response.ContentType =
CStr(ds.Tables(0).Rows(0).Item("CONTENT_TYPE"))
Context.Response.Flush()
context.Response.End()
End If
End Sub
Much appreciated for any help