stream defaul image when no image in DB

  • Thread starter Thread starter Ratman
  • Start date Start date
R

Ratman

I have a class that streams an image from a DB. If there is no image
(record then I want the class to stream a default image.

Why is this not working? It is breaking on the line of code within
the for..loop. Any help would be greatly appreciated.

bImageBinaryData is a Byte()

Thanks.

Dim oHttpContext As HttpContext
Dim sPhysicalFilePath As String =
oHttpContext.Current.Server.MapPath("../images/img-CategoryThumb.gif")

sImageName = ""
sImageContentType = ""

Dim fsDefaultThumbnail As New FileStream(sPhysicalFilePath,
FileMode.Open, FileAccess.Read)
Dim brDefaultThumbnail As New BinaryReader(fsDefaultThumbnail)
Dim iCounter As Long
Dim baDefaultThumbnail As Byte()

For iCounter = 0 To fsDefaultThumbnail.Length
baDefaultThumbnail(CType(iCounter, Integer)) =
brDefaultThumbnail.ReadByte
Next

fsDefaultThumbnail = Nothing
brDefaultThumbnail = Nothing

bImageBinaryData = baDefaultThumbnail
 
Ratman said:
I have a class that streams an image from a DB. If there is no image
(record then I want the class to stream a default image.

Why is this not working? It is breaking on the line of code within
the for..loop. Any help would be greatly appreciated.

You haven't created the actual array. I would strongly suggest reading
more than a byte at a time, too - it'll be much faster. You don't need
to use BinaryReader in this case, by the way - and you should be
closing the stream at the end so as not to leak handles.
 
Back
Top