Problems with FileStreams and images in jpeg format

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Suzanne

    Problems with FileStreams and images in jpeg format

    Hi all,

    I'm attempting to save images (that are in jpeg format) to a database
    column of type image. I've read over the Microsoft Knowledge Base
    articles for this and I can get things working when the image is in a
    gif format - but not when the image is in a jpeg format - I get the
    error that the file can not be found (& I've checked - the file is
    there)!

    My code is :
    Public Function UpLoadData(ByVa l UID As Integer)

    Dim dr As SqlDataReader
    Dim fs As New FileStream("\\I mages\image1.gi f", FileMode.Open,
    fileAccess.Read )
    Dim bytArray(CInt(f s.Length - 1)) As Byte
    fs.Read(bytArra y, 0, bytArray.Length )
    fs.Close()

    Dim params() As SqlParameter = {New SqlParameter("@ aint_UID",
    SqlDbType.Int), _
    New SqlParameter("@ aimg_Document", SqlDbType.Image ,
    bytArray.Length )}

    params(0).Value = UID
    params(1).Value = bytArray

    obj_DAL.Execute SP("usp_TestIma geInsert", params, dr,
    DAL.Type.Execut eNoQuery)
    End Function.

    Note: obj_DAL is a data access object that opens a sqlconnection and
    sets sqlcommand to a stored procedure (this bit works!).

    All this code will work as long as the image is in .gif format but not
    for .jpeg.

    What am I not doing / or doing wrong? When I debug it just gets to
    creating the FileStream and then throws the error of the file can not
    be found.

    Please help!

    Thanks
    Suzanne
  • Michael Gray

    #2
    Re: Problems with FileStreams and images in jpeg format

    Are you getting .jpg and .jpeg mixed up?

    Comment

    • MSFT

      #3
      RE: Problems with FileStreams and images in jpeg format

      Hi Suzanne,

      Are the two files (JIF and JPG) in same folder? Is it possible that you use
      a incorrect file name for the JPG file? To make sure this, I suggest you
      may check if the file really exists:

      for window application:

      Msgbox Dir("\\Images\M yJPEG.jpg")

      for asp.net application:

      Response.wrtie Dir("\\Images\M yJPEG.jpg")

      If the file exists, it will display its file name. If not, it will display
      a blank string.


      Luke
      Microsoft Online Support

      Get Secure! www.microsoft.com/security
      (This posting is provided "AS IS", with no warranties, and confers no

      rights.)

      Comment

      Working...