Hi Peter,
By some reason the method you described does not work. I've created the ASPX file with just one IMAGE box on it (MOVIETEST.ASPX) and specified as a SRC for the image box the name of second ASPX file (MOVIE.ASPX) to do all database work in the LOAD event. But what I see on the returned MOVIETEST.ASPX page is just empty image box. I've tested to display SWF file.
I am sending the code for MOVIE.ASPX file. What do you think I am doing wrong?
Imports System.Data
Imports System.Data.OleDb
Imports Oracle.DataAccess.Client
Public Class Movie
Inherits System.Web.UI.Page
Private wsDataBasesService As DataBasesService
Private sErrorMessage As String
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim lBIOTA_ID As Long
Dim lMovie_ID As Long
Dim dr As OracleDataReader
Dim cmd As OracleCommand
Dim oTmp As Object
Dim i As Integer
Dim k As Integer
Dim sCommandText As String 'the command text string
Dim iPos As Integer
Dim iLen As Integer
Dim lReturn As Long
Dim sTmp As String
Dim sFileExtention As String
Dim sFileName As String
Dim byteData As Byte()
Dim lLength As Long
'initialization:
sErrorMessage = ""
'''''lBIOTA_ID = CLng(Session("BIOTA_ID")) 'LIVE!!!!!!!!!!!!!!!!!!!!!!!!!!!
'''''lMovie_ID = CLng(Session("MOVIE_ID")) 'LIVE!!!!!!!!!!!!!!!!!!!!!!!!!!!
lBIOTA_ID = 8290 'FOR TEST ONLY!!!!!!!!!!!!!!!!!!!!!!!
lMovie_ID = 1 'FOR TEST ONLY!!!!!!!!!!!!!!!!!!!!!!!
'Create the connection to the datasource:
'wsDataBasesService = New DataBaseWebService.DataBasesService
wsDataBasesService = New DataBasesService
If wsDataBasesService.LAZARUS_OpenConnection("USERID" , "PASSWORD") = 1 Then
Try
sCommandText = "SELECT f.MOVIE_OBJECT,f.MOVIE_OBJECT_NAME,f.MOVIE_OBJECT_ SIZE FROM LAZARUS.MEDIAMOVIE f WHERE f.BIOTA_ID=" & CStr(lBIOTA_ID) & " AND f.MOVIE_ID=" & CStr(lMovie_ID) & ""
cmd = New OracleCommand(sCommandText, CType(wsDataBasesService.GetLAZARUSConnection(), OracleConnection))
dr = cmd.ExecuteReader(CommandBehavior.Default)
While (dr.Read = True)
'iterate over all fields:
For i = 0 To dr.FieldCount - 1
Select Case dr.GetName(i)
Case "MOVIE_OBJECT"
If Not dr.GetValue(i) Is DBNull.Value Then
'fetch the value of ORACLE field ito the byte-array:
byteData = CType(dr.GetValue(i), Byte())
Else
oTmp = Nothing
cmd = Nothing
If dr.IsClosed = False Then
dr.Close()
End If
wsDataBasesService.LAZARUS_CloseConnection()
wsDataBasesService = Nothing
Exit Sub
End If
Case "MOVIE_OBJECT_SIZE"
If Not dr.GetValue(i) Is DBNull.Value Then
If Not dr.GetValue(i) Is DBNull.Value Then
lLength = CType(dr.GetValue(i), Long)
End If
End If
Case "MOVIE_OBJECT_NAME"
If Not dr.GetValue(i) Is DBNull.Value Then
oTmp = CType(dr.GetValue(i), String)
sFileName = oTmp
iPos = InStrRev(sFileName, ".")
If iPos <> 0 Then
sFileExtention = Mid(sFileName, iPos + 1)
'do clean up:
oTmp = Nothing
Else
'do clean up:
oTmp = Nothing
cmd = Nothing
If dr.IsClosed = False Then
dr.Close()
End If
wsDataBasesService.LAZARUS_CloseConnection()
wsDataBasesService = Nothing
Response.WriteFile("SorryNoImagePage.asp")
Exit Sub
End If
Else
oTmp = Nothing
cmd = Nothing
If dr.IsClosed = False Then
dr.Close()
End If
wsDataBasesService.LAZARUS_CloseConnection()
wsDataBasesService = Nothing
Response.WriteFile("SorryNoImagePage.asp")
Exit Sub
End If
Case Else
'do clean up...
oTmp = Nothing
cmd = Nothing
If dr.IsClosed = False Then
dr.Close()
End If
wsDataBasesService.LAZARUS_CloseConnection()
wsDataBasesService = Nothing
Session("Message") = "ERROR on reading field values with DataReader. Contact customer support,please. "
Response.Redirect("ErrorForm.aspx", False)
Exit Sub
End Select
'do clean up...
oTmp = Nothing
Next
End While
'Display the contents of the record as an image:
Response.Expires = 0
Response.Buffer = True
Response.Clear()
If UCase(sFileExtention) = "GIF" Then
Response.ContentType = "image/gif"
ElseIf UCase(sFileExtention) = "JPEG" Or UCase(sFileExtention) = "JPG" Then
Response.ContentType = "image/jpeg"
ElseIf UCase(sFileExtention) = "PDF" Then
Response.ContentType = "text/html"
ElseIf UCase(sFileExtention) = "AVI" Then
Response.ContentType = "video/x-msvideo"
ElseIf UCase(sFileExtention) = "SWF" Then
Response.ContentType = "application/x-shockwave-flash"
End If
Response.BinaryWrite(byteData)
'''''Response.End()
'do clean up...
oTmp = Nothing
cmd = Nothing
If dr.IsClosed = False Then
dr.Close()
End If
wsDataBasesService.LAZARUS_CloseConnection()
wsDataBasesService = Nothing
Catch ex As Exception
'do clean up...
If Not wsDataBasesService.GetLAZARUSConnection() Is Nothing Then
If wsDataBasesService.LAZARUS_ConnectionState() = 1 Then
If dr.IsClosed = False Then
dr.Close()
dr.Dispose()
End If
wsDataBasesService.LAZARUS_CloseConnection()
wsDataBasesService.Dispose()
wsDataBasesService = Nothing
End If
End If
cmd = Nothing
'ERROR on reading field values with DataReader
Session("Message") = ex.Message
Response.Redirect("ErrorForm.aspx", False)
Exit Sub
End Try
Else
'ERROR opening the connection to the DataSource
Session("Message") = "ERROR opening the connection to the DataSource. Contact customer support,please. "
Response.Redirect("ErrorForm.aspx", False)
Exit Sub
End If
End Sub
End Class
The "DataBasesService" is the separate class I've created to do all database related jobs.
Thanks in advance,
Dmitriy :)
